Help

how do you make if the item on the menu was selected by user and print its bill.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <iomanip>
using namespace std;
struct menuItemType
{
    string menuItem;
    double menuPrice;
};
void getData(menuItemType menuList[8]);
void showMenu (menuItemType menuList[8]);
void printCheck (menuItemType menulist[8]);

int main()
{
    char c;
    menuItemType menuList[8];
    getData(menuList);
    showMenu(menuList);
    int n = n - 1;
    do{
        cout<<"What is your order? \n";
        cout<<"Enter Item: ";
        cin>>n;
        cout<<"Do you still want to order another item?\n";
        cout<<"Y for Yes.\nN for No.\n";
        cout<<"Answer: ";
        cin>>c;
        cout<<"\n";
    }while (c == 'y' || c == 'Y');
    printCheck(menuList);

    return 0;
}
void getData(menuItemType menuList[8])
{
    menuList[0].menuItem = "Plain Egg";
	menuList[0].menuPrice = 1.45;
	menuList[1].menuItem = "Bacon and Egg";
	menuList[1].menuPrice = 2.45;
	menuList[2].menuItem = "Muffin";
	menuList[2].menuPrice = 0.99;
	menuList[3].menuItem = "French Toast";
	menuList[3].menuPrice = 1.99;
	menuList[4].menuItem = "Fruit Basket";
	menuList[4].menuPrice = 2.49;
	menuList[5].menuItem = "Cereal";
	menuList[5].menuPrice = 0.69;
	menuList[6].menuItem = "Coffee";
	menuList[6].menuPrice = 0.50;
	menuList[7].menuItem = "Tea";
	menuList[7].menuPrice = 0.75;
}
void showMenu(menuItemType menuList[8])
{
    cout<<"Welcome to your local restaurant!"<<endl;
    cout<<"-x-x-x-x-x-Menu-x-x-x-x-x-"<<endl;
    cout<<"1. Plain Egg "<<setw(13)<<"$1.45"<<endl;
    cout<<"2. Bacon and Egg "<<setw(9)<<"$2.45"<<endl;
    cout<<"3. Muffin "<<setw(16)<<"$0.99"<<endl;
    cout<<"4. French Toast "<<setw(10)<<"$1.99"<<endl;
    cout<<"5. Fruit Basket "<<setw(10)<<"$2.49"<<endl;
    cout<<"6. Cereal "<<setw(16)<<"$0.69"<<endl;
    cout<<"7. Coffee "<<setw(16)<<"$0.50"<<endl;
    cout<<"8. Tea "<<setw(19)<<"$0.75"<<endl;
    cout<<"-x-x-x-x-x-x-x-x-x-x-x-x-x\n"<<endl;
}
void printCheck(menuItemType menuList[8])
{
    double tax = .05;
    double taxAmount;
    double total = 0;
    cout<<"-x-x-x-x-BILL-x-x-x-x-"<<endl;
    for (int x=0;x<8;x++){
        cout<<menuList[x].menuItem<<"    $"<<menuList[x].menuPrice;
        total = total + menuList[x].menuPrice;
    }
    taxAmount = tax*total;
    cout<<"Tax: "<<tax;
    cout<<"Amount Due: "<<total + taxAmount;
}
Last edited on
ParadOx22 please ask your question again, maybe a different way, Sorry I can't understand your English question.
Hello ParadOx22,

The first thing that is missing is the header file "<string>". With out this you will have a problem printing any "std::string".

Line 3. It is best not to use this. It WILL get you in trouble some day. It is easier to learn what is in the "std" namespace now rather than later.

Line 19. As I thought this would not allow the program to compile because "n" starts with no value before you use it. You would be better off using int n{}; which is the same as int n = 0;.

The function getData() is OK to load the array.

You are sending menuItemType menuList[8] to the function showMenu, but there is no need for this and you do not use this array in this function.

In the function printCheck() you send the array menuList, but there is no real need for this array here. Then you use this array to print the check, but what is the order did not order all of these items?

In main and in the printCheck() function what you need is an array or vector to keep track of what was ordered. As it is "n" holds the last item ordered only. Anything before that is over written each time through the do/while loop.

You have a good start to your program, but need to rethink what you need to do and how to do it.

Also a few blank lines in your code would make it easier to read.

Hope that helps,

Andy
Topic archived. No new replies allowed.