HELP

Okay i wrote this program and and i cant figure out how to list the items so if you buy a item more them once it would list the item name again it will just say 2 beside it. like for this prgram if you buy 2 coffees it wouldnt say coffee, coffee it will say 2 coffee.


#include
#include
#include

const int size = 8;

//structure menu.
struct menuItem
{
string item;
double price;
};
//Voided Functions
void showMenu(struct menuItem BreakFastItem[size]);
void getData(struct menuItem BreakFastItem[size]);

int main()
{

//Setup output to display doubles to 2 decimal places
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

//Calling from structure
menuItem BreakFastItem[size];
string name;
cout << "Please enter your name: ";
cin >> name;
system("CLS");
cout << name<<" Welcome to Johnny's restaurant, here is your menu"<<"
"<<"
";

//Calling voided functions
showMenu(BreakFastItem);
getData(BreakFastItem);


system("PAUSE");
return 0;
}
//Menu
void showMenu(struct menuItem BreakFastItem[size])
{
cout << "+------------------------------------+"<<"
";
cout << "| * WELCOME TO JOHNNY'S RESTAURANT * |"<<"
";
cout << "| ~~~~~~~~~~ BEAKFAST MENU ~~~~~~~~~ |"<<"
";
cout << "+------------------------------------+"<<"
";
cout << "| ITEM # | ITEM | PRICE |"<<"
";
cout << "| ~~~~~~ | ~~~~ | ~~~~~ |"<<"
";
cout << "| 1 | Plain Egg | $1.45 |"<<"
";
cout << "| 2 | Bacon and Egg | $2.45 |"<<"
";
cout << "| 3 | Muffin | $0.99 |"<<"
";
cout << "| 4 | French Toast | $1.99 |"<<"
";
cout << "| 5 | Fruit Basket | $2.49 |"<<"
";
cout << "| 6 | Cereal | $0.69 |"<<"
";
cout << "| 7 | Coffee | $0.50 |"<<"
";
cout << "| 8 | Tea | $0.75 |"<<"
";
cout << "+------------------------------------+"<<"
";
}

void getData(struct menuItem BreakFastItem[size])
{
int amountitem;

cout <<" Please enter the amount of items you would like to get: ";
cin >> amountitem;
cout <<"

";

double food[amountitem];
double total;

for (int counter = 0; counter<amountitem; counter++)
{
cout <<"Please enter the item number you would like to get: ";
cin >> food[counter];

if (food[counter] < 1 || food[counter] >= 9)
{
cout << "Sorry this is a incorrect number please re-enter the number(0-7): ";
cin>>food[counter];
}
}
cout <<"

";
system("CLS");
cout << " Here is your bill "<<"
";
cout << "+-----------------------+
";
cout << "| JOHNNY'S RESTAURANT |
";
cout <<"| |
";

for (int counter = 0; counter<amountitem; counter++)
{
if (food[counter] == 1)
{
total = total + 1.45;
cout << "| Plain Egg "<<" 1.45 |
";
}
else if (food[counter] == 2)
{
total = total + 2.45;
cout << "| Bacon and Egg"<<" 2.45 |
";
}
else if (food[counter] == 3)
{
total = total + 0.99;
cout << "| Muffin"<<" 0.99 |
";
}
else if (food[counter] == 4)
{
total = total + 1.99;
cout << "| French Toast"<<" 1.99 |
";
}
else if (food[counter] == 5)
{
total = total + 2.49;
cout << "| Fruit Basket"<<" 2.49 |
";
}
else if (food[counter] == 6)
{
total = total + 0.69;
cout << "| Cereal"<<" 0.69 |
";
}
else if (food[counter] == 7)
{
total = total + 0.50;
cout << "| Coffee"<<" 0.50 |
";
}
else if (food[counter] == 8)
{
total = total + 0.75;
cout << "| Tea"<<" 0.75 |
";
}
}
cout <<"| |
";
cout <<"| SubTotal: "<<total<<" |
";

double tax;
tax = (total * 5)/100;
cout << "| Tax: "<<tax<<" |
";
total = total + tax;
cout << "| Total: "<<total<<" |
";
cout <<"| |
";
cout << "|Thank you for coming to"<<"|
";
cout << "| Johnny's Restaurant"<<" |
";
cout << "| Please come again"<<" |
";
cout << "+-----------------------+
";
endl;
}

Comments

  • add quantity to the menuItem structure. Search the array of menuItem structures, if one is already present for the desired food item then just increment the quantity instead of adding a new one. That makes it almost trival to show the 2 coffee.


  • I did this but i doesnt want to work, im still lost

  • : Okay i wrote this program and and i cant figure out how to list the items so if you buy a item more them once it would list the item name again it will just say 2 beside it. like for this prgram if you buy 2 coffees it wouldnt say coffee, coffee it will say 2 coffee.
    :
    [blue]
    Please use [leftbr]code[rightbr][leftbr]/code[rightbr]
    when posting code.[/blue]
    [code]

    : #include
    : #include
    : #include
    :
    : const int size = 8;
    :
    : //structure menu.
    : struct menuItem
    : {
    : string item;
    : double price;
    : };
    : //Voided Functions
    [blue]//What is the 'struct' keyword doing here?[/blue]
    : void showMenu(struct menuItem BreakFastItem[size]);
    : void getData(struct menuItem BreakFastItem[size]);
    :
    : int main()
    : {
    :
    : //Setup output to display doubles to 2 decimal places
    : cout.setf(ios::fixed);
    : cout.setf(ios::showpoint);
    : cout.precision(2);
    :
    : //Calling from structure
    : menuItem BreakFastItem[size];
    : string name;
    : cout << "Please enter your name: ";
    : cin >> name;
    : system("CLS");
    : cout << name<<" Welcome to Johnny's restaurant, here is your menu"<<"
    "<<"
    ";
    :
    : //Calling voided functions
    : showMenu(BreakFastItem);
    : getData(BreakFastItem);
    :
    :
    : system("PAUSE");
    : return 0;
    : }
    : //Menu
    : void showMenu(struct menuItem BreakFastItem[size])
    : {
    : cout << "+------------------------------------+"<<"
    ";
    : cout << "| * WELCOME TO JOHNNY'S RESTAURANT * |"<<"
    ";
    : cout << "| ~~~~~~~~~~ BEAKFAST MENU ~~~~~~~~~ |"<<"
    ";
    : cout << "+------------------------------------+"<<"
    ";
    : cout << "| ITEM # | ITEM | PRICE |"<<"
    ";
    : cout << "| ~~~~~~ | ~~~~ | ~~~~~ |"<<"
    ";
    : cout << "| 1 | Plain Egg | $1.45 |"<<"
    ";
    : cout << "| 2 | Bacon and Egg | $2.45 |"<<"
    ";
    : cout << "| 3 | Muffin | $0.99 |"<<"
    ";
    : cout << "| 4 | French Toast | $1.99 |"<<"
    ";
    : cout << "| 5 | Fruit Basket | $2.49 |"<<"
    ";
    : cout << "| 6 | Cereal | $0.69 |"<<"
    ";
    : cout << "| 7 | Coffee | $0.50 |"<<"
    ";
    : cout << "| 8 | Tea | $0.75 |"<<"
    ";
    : cout << "+------------------------------------+"<<"
    ";
    : }
    :
    : void getData(struct menuItem BreakFastItem[size])
    : {
    : int amountitem;
    :
    : cout <<" Please enter the amount of items you would like to get: ";
    : cin >> amountitem;
    : cout <<"

    ";
    :
    [red] double food[amountitem]; // This is an error.
    // Arrays [b]must[/b] be created with a constant.[/red]
    : double total;
    :
    : for (int counter = 0; counter<amountitem; counter++)
    : {
    : cout <<"Please enter the item number you would like to get: ";
    : cin >> food[counter];
    :
    : if (food[counter] < 1 || food[counter] >= 9)
    : {
    : cout << "Sorry this is a incorrect number please re-enter the number(0-7): ";
    : cin>>food[counter];
    : }
    : }
    : cout <<"

    ";
    : system("CLS");
    : cout << " Here is your bill "<<"
    ";
    : cout << "+-----------------------+
    ";
    : cout << "| JOHNNY'S RESTAURANT |
    ";
    : cout <<"| |
    ";
    :
    [green]
    // Heres an easy way (may be better ways..) that serches
    // through the food list, and stores the number of items
    // in the apropriate index.
    int numItems[5]={0};
    for (int nCounter=0; nCounter<amountitem; nCounter++)
    {
    if (food[nCounter]==1)
    numItems[0]++;
    if (food[nCounter]==2)
    numItems[1]++;
    if (food[nCounter]==3)
    numItems[2]++;
    if (food[nCounter]==4)
    numItems[3]++;
    if (food[nCounter]==5)
    numItems[4]++;
    }[/green]

    : for (int counter = 0; counter<amountitem; counter++)
    : {
    : if (food[counter] == 1)
    : {
    : total = total + 1.45;
    [green]// Add << numItems[counter-1] for each of these..[/green]
    cout << "| " [green]<< numItems[0][/green] << " Plain Egg "<<" 1.45 |
    ";
    : }
    : else if (food[counter] == 2)
    : {
    : total = total + 2.45;
    : cout << "| Bacon and Egg"<<" 2.45 |
    ";
    : }
    : else if (food[counter] == 3)
    : {
    : total = total + 0.99;
    : cout << "| Muffin"<<" 0.99 |
    ";
    : }
    : else if (food[counter] == 4)
    : {
    : total = total + 1.99;
    : cout << "| French Toast"<<" 1.99 |
    ";
    : }
    : else if (food[counter] == 5)
    : {
    : total = total + 2.49;
    : cout << "| Fruit Basket"<<" 2.49 |
    ";
    : }
    : else if (food[counter] == 6)
    : {
    : total = total + 0.69;
    : cout << "| Cereal"<<" 0.69 |
    ";
    : }
    : else if (food[counter] == 7)
    : {
    : total = total + 0.50;
    : cout << "| Coffee"<<" 0.50 |
    ";
    : }
    : else if (food[counter] == 8)
    : {
    : total = total + 0.75;
    : cout << "| Tea"<<" 0.75 |
    ";
    : }
    : }
    : cout <<"| |
    ";
    : cout <<"| SubTotal: "<<total<<" |
    ";
    :
    : double tax;
    : tax = (total * 5)/100;
    : cout << "| Tax: "<<tax<<" |
    ";
    : total = total + tax;
    : cout << "| Total: "<<total<<" |
    ";
    : cout <<"| |
    ";
    : cout << "|Thank you for coming to"<<"|
    ";
    : cout << "| Johnny's Restaurant"<<" |
    ";
    : cout << "| Please come again"<<" |
    ";
    : cout << "+-----------------------+
    ";
    [red]cout <<[/red] endl;
    : }
    [/code][blue]
    btw, whats with the small font?
    Does anyone else experience this, or is just me?[/blue]

  • [blue]
    : btw, whats with the small font?
    : Does anyone else experience this, or is just me?[/blue]
    :

    I see the first few lines in a smaller font then the rest. I'm using Firefox 1.04 browser.
  • : I did this but i doesnt want to work, im still lost
    :
    :
    you didn't try hard enough :-)
  • Sweet it works but its still double printing the works like if the person gets 3 coffees it will say on the bill 3 coffee, 3 coffee, 3 coffee why would it be doing this.
  • : [blue]
    : : btw, whats with the small font?
    : : Does anyone else experience this, or is just me?[/blue]
    : :
    :
    : I see the first few lines in a smaller font then the rest. I'm using Firefox 1.04 browser.
    :


    [code]const int [red]size[/red] = 8

    struct menuItem
    {
    string item;
    double price;
    };
    //Voided Functions
    void showMenu(struct menuItem BreakFastItem[ [red]size[/red] ]);
    [/code]

    I bet that is what was originally in the code minus the extra spaces in between the word "size" and the brackets. That tag apparently causes a resizing of the font. I've never tried it but I bet you could put a "=10" or some such in there and then also have a "[ /size ]" tag just like the other formatting tags.
  • : : [blue]
    : : : btw, whats with the small font?
    : : : Does anyone else experience this, or is just me?[/blue]
    : : :
    : :
    : : I see the first few lines in a smaller font then the rest. I'm using Firefox 1.04 browser.
    : :
    :
    :
    : [code]const int [red]size[/red] = 8
    :
    : struct menuItem
    : {
    : string item;
    : double price;
    : };
    : //Voided Functions
    : void showMenu(struct menuItem BreakFastItem[ [red]size[/red] ]);
    : [/code]
    :
    : I bet that is what was originally in the code minus the extra spaces in between the word "size" and the brackets. That tag apparently causes a resizing of the font. I've never tried it but I bet you could put a "=10" or some such in there and then also have a "[ /size ]" tag just like the other formatting tags.
    :
    [blue]
    Thats probably it..I forgot about [leftbr]size[rightbr].

    According to "style codes", you could set the size from 1..5.
    [/blue]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories