Student needing help please in my C++ class

Pages: 12
Hello XzainKarrito,

You may find something useful here http://www.cplusplus.com/forum/beginner/277265/ Not the same program, but may help.

When going over your code it is very hard not to notice:
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
void getData(ITEM& menuList)  // <--- Changed.
{
    menuItemType plainEgg;
    menuItemType baconEgg;
    menuItemType muffin;
    menuItemType frenchToast;
    menuItemType fruitBasket;
    menuItemType cereal;
    menuItemType coffee;
    menuItemType tea;


    plainEgg.menuItem = "Plain Egg";
    plainEgg.menuPrice = 1.45;
    baconEgg.menuItem = "Bacon and Egg";
    baconEgg.menuPrice = 2.45;
    muffin.menuItem = "Muffin";
    muffin.menuPrice = 0.99;
    frenchToast.menuItem = "French Toast";
    frenchToast.menuPrice = 1.99;
    fruitBasket.menuItem = "Fruit Basket";
    fruitBasket.menuPrice = 2.49;
    cereal.menuItem = "Cereal";
    cereal.menuPrice = 0.69;
    coffee.menuItem = "Coffee";
    coffee.menuPrice = 0.50;
    tea.menuItem = "Tea";
    tea.menuPrice = 0.75;

    menuList[0] = plainEgg;
    menuList[1] = baconEgg;
    menuList[2] = muffin;
    menuList[3] = frenchToast;
    menuList[4] = fruitBasket;
    menuList[5] = cereal;
    menuList[6] = coffee;
    menuList[7] = tea;
}

Changing the struct to:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
constexpr int MAXSIZE{ 8 };  // <--- You can make more use of it here.

//struct for menuItemType
struct menuItemType
{
    string menuItem;
    double menuPrice;

    void SetValues(std::string item, double price)
    {
        menuItem = item;
        menuPrice = price;
    }
};

using ITEM = menuItemType[MAXSIZE];

void getData(ITEM& menuList);

The function then becomes:
1
2
3
4
5
6
void getData(ITEM& menuList)
{
    menuList[0].SetValues("Plain Egg", 1.45 );
    menuList[1].SetValues("Bacon and Egg", 2.45);
    // <--- The rest here.
}

Or againtry has another alternative.

This is the output I get:

Welcome to Johnny's Resturant
You can make up to 8 single order selections
[ 1]Plain Egg$1.45
[ 2]Bacon and Egg$2.45
[ 3]Muffin$0.99
[ 4]French Toast$1.99
[ 5]Fruit Basket$2.49
[ 6]Cereal$0.69
[ 7]Coffee$0.5
[ 8]Tea$0.75
Do you want to make selection Y/y (Yes), N/n (No):
y
Enter item number
1
Do you want to make selection Y/y (Yes), N/n (No):
y
Enter item number
2
Do you want to make selection Y/y (Yes), N/n (No):
y
Enter item number
3
Do you want to make selection Y/y (Yes), N/n (No):
n
Thanks for eating at Johnny'sCustomer check:
Plain Egg $1.45
Bacon and Egg$2.45
Muffin    $0.99
Tax           0.245
Total         5.13


You really need to make it look better.

I think it is required that you output the line "Do you want to make selection Y/y (Yes), N/n (No): ". If you leave off the "endl", better to prefer using (\n), the input will be on the same line as the prompt.

Andy
I finally got it working properly I had to go changes some stuff around to make it look right thanks a lot for the advice and help.

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cctype>

using namespace std;

//struct for menuItemType
struct menuItemType
{
    string menuItem;
    double menuPrice;
};

void getData(menuItemType menuList[]);
void showMenu(menuItemType menuList[], int x);
void printCheck(menuItemType menuList[], int menuOrder[], int x);

int main()
{

    const int menuItems = 8;
    menuItemType menuList[menuItems];
    int menuOrder[menuItems] = {0};
    int orderChoice = 0;
    bool ordering = true;
    char choice;
    int x = 0;
    
   
    
    getData(menuList);
    
    
    showMenu(menuList, menuItems);
    while(ordering || toupper (choice) == 'Y')
    {
       
       if ( x < 1 ) 
        {  
          cout << "You can make up to 8 single order selections" << endl;
          cout << "Do you want to make selection Y/y (Yes), N/n (No): ";
          x++;
           cin >> choice;
            switch (choice) 
            {
            case 'y':
            case 'Y':
              cout << "Enter item number";
              cin >> orderChoice;
              menuOrder[orderChoice - 1] += 1;
              break;
            case 'n':
            case 'N':
              ordering = false;
            break;
            } 
        }
        else (x >2);
          {
            cout<< "Select another item Y/y (Yes), N/n (No): ";
          
            cin >> choice;
            switch (choice) 
            {
            case 'y':
            case 'Y':
              cout << "Enter item number";
              cin >> orderChoice;
              menuOrder[orderChoice - 1] += 1;
              break;
            case 'n':
            case 'N':
              ordering = false;
            break;
            }
          }
    
        
        
    }
      printCheck(menuList, menuOrder, menuItems);
      cin.ignore(2);
        return 0;    
        
    
}    
    
    
    
    void getData(menuItemType menuList[])
    {
    
        menuItemType plainEgg;
        menuItemType baconEgg;
        menuItemType muffin;
        menuItemType frenchToast;
        menuItemType fruitBasket;
        menuItemType cereal;
        menuItemType coffee;
        menuItemType tea;
        
        
        plainEgg.menuItem = "Plain Egg";
        plainEgg.menuPrice = 1.45;
        baconEgg.menuItem = "Bacon and Egg";
        baconEgg.menuPrice = 2.45;
        muffin.menuItem = "Muffin";
        muffin.menuPrice = 0.99;
        frenchToast.menuItem = "French Toast";
        frenchToast.menuPrice = 1.99;
        fruitBasket.menuItem = "Fruit Basket";
        fruitBasket.menuPrice = 2.49;
        cereal.menuItem = "Cereal";
        cereal.menuPrice = 0.69;
        coffee.menuItem = "Coffee";
        coffee.menuPrice = 0.50;
        tea.menuItem = "Tea";
        tea.menuPrice = 0.75;
        
        menuList[0] = plainEgg;
        menuList[1] = baconEgg;
        menuList[2] = muffin;
        menuList[3] = frenchToast;
        menuList[4] = fruitBasket;
        menuList[5] = cereal;
        menuList[6] = coffee;
        menuList[7] = tea;
    }
    
    void showMenu(menuItemType menuList[], int x)
    {
    
        int count;
        
        cout << "Welcome to Johnny's Resturant" << endl;
        cout << "----------MENU ITEMS----------" << endl;
        for(count = 0; count < x; count++)
        {
            cout << setw(2) << left << "[" << count + 1 << "]"
                 << menuList[count].menuItem << '$'
                 << menuList[count].menuPrice << endl;
        }
    }
    
    void printCheck(menuItemType menuList[], int menuOrder[], int menuItems)
    {
        double checkTotal = 0;
        double checkTax = 0;
        const double TAX = .05;
        cout << "Welcome to Johnny's Resturaunt" << endl;
        for(int i = 0; i < menuItems; i++)
        {
            if(menuOrder[i] > 0) {
                cout << setprecision(3) << setw(10) << left << menuList[i].menuItem
                     << '$' << (menuList[i].menuPrice * menuOrder[i]) << endl;
                checkTotal += (menuList[i].menuPrice * menuOrder[i]);
            }
        }
        checkTax = checkTotal * TAX;
        checkTotal += checkTax;
        cout << fixed << setprecision(2) << setw(14) << left << "Tax" << '$' <<checkTax << endl
             << fixed << setprecision(2) << setw(14) << left << "Amount Due" << '$' << checkTotal << endl;
    }


And now it shows what it is supposed to.

Welcome to Johnny's Resturant
----------MENU ITEMS----------
[ 1]Plain Egg$1.45
[ 2]Bacon and Egg$2.45
[ 3]Muffin$0.99
[ 4]French Toast$1.99
[ 5]Fruit Basket$2.49
[ 6]Cereal$0.69
[ 7]Coffee$0.5
[ 8]Tea$0.75
You can make up to 8 single order selections
Do you want to make selection Y/y (Yes), N/n (No): y
Enter item number1
Select another item Y/y (Yes), N/n (No): y
Enter item number2
Select another item Y/y (Yes), N/n (No): n
Welcome to Johnny's Resturaunt
Plain Egg $1.45
Bacon and Egg$2.45
Tax $0.20
Amount Due $4.10
Topic archived. No new replies allowed.
Pages: 12