Error when compiling

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paul lee
    New Member
    • Feb 2012
    • 1

    Error when compiling

    im trying to make a restaurant menu program but i keep getting

    "expected constructor, destructor, or type conversion before '<<' token" when i compile. any all would be much appreciated



    /*
    Name: Paul Pee
    Date: 2/11/12
    Description: Breakfast Programs
    */
    #include <iostream>
    #include <string>
    #include <iomanip>
    using namespace std;

    struct menuItem
    {
    string menuChoice;
    double menuPrice;
    };

    struct selectedItem
    {
    string menuChoice;
    double menuPrice;
    };



    void getData(menuIte m menuList[7]) //Loading data into the struct
    {
    menuList[0].menuChoice="Pl ain Egg";
    menuList[0].menuPrice = 1.45;

    menuList[1].menuChoice = "Bacon and Egg";
    menuList[1].menuPrice = 2.45;

    menuList[2].menuChoice = "Muffin";
    menuList[2].menuPrice = 0.99;

    menuList[3].menuChoice = "French Toast";
    menuList[3].menuPrice = 1.99;

    menuList[4].menuChoice = "Cereal";
    menuList[4].menuPrice = 1.69;

    menuList[5].menuChoice = "Coffee";
    menuList[5].menuPrice = 1.25;

    menuList[6].menuChoice = "Tea";
    menuList[6].menuPrice = 1.25;
    }

    //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    void showMenu(menuIt em menuList[7]) //function shows a customer to select items from the menu
    {
    cout << "What would you like for breakfast?"<<en dl;

    for (int i=0;i<7;i++)
    {
    cout << i+1 << ": " << left << setw(18) <<menuList[i].menuChoice << right << setw(14) << menuList[i].menuPrice << endl;
    }

    cout<<"Hit 0 to complete your order" << endl;
    }

    //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    double iTotal ( double price , int amt)
    {
    double sp;
    sp = price * amt;
    return (sp);
    }

    //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    void printCheck(menu Item menuList[7])
    {
    int amt;
    double price;
    double eggtotal, mtotal, betotal, cetotal, cototal, fttotal, ttotal =0;
    double total = 0.0;
    int amtegg, amtbe, amtm, amtft, amtce, amtco, amtt = 0;
    int choice = 9;
    double tax = 0.05;
    double pretotal = eggtotal + betotal + mtotal + fttotal + cetotal + cototal +ttotal;
    double taxamt = pretotal * tax;
    double fnltotal = pretotal + tax;

    selectedItem selectedChoice[7];
    for(int e=0;e<7;e++)
    {
    selectedChoice[e].menuChoice=' ';
    selectedChoice[e].menuPrice=0;
    }

    cout << "Please make your selections." << endl;

    while (choice != 0)
    cin >> choice;

    switch(choice)
    {
    case 1:
    cout << setw(53)<< menuList[0].menuChoice <<" " << menuList[0].menuPrice<<end l;

    if (amtegg == 0)
    {
    selectedChoice[0].menuPrice=menu List[0].menuPrice;
    selectedChoice[0].menuChoice=men uList[0].menuChoice;
    amtegg++;
    }
    else
    amtegg++;

    price = menuList[0].menuPrice;
    amt = amtegg;
    eggtotal = iTotal (price, amt);
    break;

    case 2:
    cout << setw(53)<< menuList[1].menuChoice <<" " << menuList[1].menuPrice<<end l;

    if (amtbe == 0)
    {
    selectedChoice[1].menuPrice=menu List[1].menuPrice;
    selectedChoice[1].menuChoice=men uList[1].menuChoice;
    amtbe++;
    }
    else
    amtbe++;

    price = menuList[1].menuPrice;
    amt = amtbe;
    betotal = iTotal (price, amt);
    break;

    case 3:
    cout << setw(53)<< menuList[2].menuChoice <<" " << menuList[2].menuPrice<<end l;

    if (amtm == 0)
    {
    selectedChoice[2].menuPrice=menu List[2].menuPrice;
    selectedChoice[2].menuChoice=men uList[2].menuChoice;
    amtm++;
    }
    else
    amtm++;

    price = menuList[2].menuPrice;
    amt = amtm;
    mtotal = iTotal (price, amt);
    break;

    case 4:
    cout << setw(53)<< menuList[3].menuChoice <<" " << menuList[3].menuPrice<<end l;

    if (amtft == 0)
    {
    selectedChoice[3].menuPrice=menu List[3].menuPrice;
    selectedChoice[3].menuChoice=men uList[3].menuChoice;
    amtft++;
    }
    else
    amtft++;

    price = menuList[3].menuPrice;
    amt = amtft;
    fttotal = iTotal (price, amt);
    break;

    case 5:
    cout << setw(53)<< menuList[4].menuChoice <<" " << menuList[4].menuPrice<<end l;

    if (amtce == 0)
    {
    selectedChoice[4].menuPrice=menu List[4].menuPrice;
    selectedChoice[4].menuChoice=men uList[4].menuChoice;
    amtce++;
    }
    else
    amtce++;

    price = menuList[4].menuPrice;
    amt = amtce;
    cetotal = iTotal (price, amt);
    break;

    case 6:
    cout << setw(53)<< menuList[5].menuChoice <<" " << menuList[5].menuPrice<<end l;

    if (amtco == 0)
    {
    selectedChoice[5].menuPrice=menu List[5].menuPrice;
    selectedChoice[5].menuChoice=men uList[5].menuChoice;
    amtco++;
    }
    else
    amtco++;

    price = menuList[5].menuPrice;
    amt = amtco;
    cototal = iTotal (price, amt);
    break;

    case 7:
    cout << setw(53)<< menuList[6].menuChoice <<" " << menuList[6].menuPrice<<end l;

    if (amtt == 0)
    {
    selectedChoice[6].menuPrice=menu List[6].menuPrice;
    selectedChoice[6].menuChoice=men uList[6].menuChoice;
    amtt++;
    }
    else
    amtt++;

    price = menuList[6].menuPrice;
    amt = amtt;
    ttotal = iTotal (price, amt);
    break;

    case 0:
    break;

    default:
    cout << "That choice is not on the menu!!" << endl;
    break;
    }
    }

    cout << " Welcome to Johnny's Restaurant "<<endl;
    cout << " Your Bill "<<endl;
    cout << endl;
    cout << setw(20)<<"Menu Item "<<setw(20)<<"P rice(USD $)"<<endl;

    for(int f=0;f<7;f++) //Extracts data from struct 2 and outputs them on the screen
    {
    if (selectedChoice[f].menuChoice==" ")
    f++;
    else
    cout<<setw(20)< <selectedMenu[f].menuChoice<<se tw(20)<<selecte dChoice[f].menuPrice<<end l;
    }
    cout<<endl;
    cout<<setw(20)< <"Taxes"<<setpr ecision(2)<<set w(35)<<taxamt<< endl;
    cout<<endl;
    cout<<setw(20)< <"Amount Due"<<setprecis ion(3)<<setw(35 )<<fnltotal<<en dl;
    cout<<endl;
    }



    int main()
    {

    menuItem menuList[7];

    getData(menuLis t);
    showMenu(menuLi st);
    printCheck(menu List);






    system("Pause") ;
    return 0;
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    When you use the << operator with a menuChoice variable, the compiler is trying to tell you that it doesn't know how to use the << operator with a string object.

    You neeed to convert the string from a C++ string to a C string in order to display it:

    Code:
    cout << var.menuChoice.c_str();

    Comment

    Working...