### Student needing help please in my C++ class

Pages: 12
I am having an issue with this assignment.

Write a program to help a local restaurant automate its breakfast billing system. The program should do the following:

Show the customer the different breakfast items offered by the restaurant.
Allow the customer to select more than one item from the menu.
Calculate and print the bill.
Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right of the item):

food Price
Plain Egg \$1.45
Bacon and Egg \$2.45
Muffin \$0.99
French Toast \$1.99
Cereal \$0.69
Coffee \$0.50
Tea \$0.75
Use an array menuList of type menuItemType, as defined in Programming Exercise 3. Your program must contain at least the following functions:

Function showMenu: This function shows the different items offered by the restaurant and tells the user how to select the items.
Function printCheck: This function calculates and prints the check. (Note that the billing amount should include a 5% tax.)
A sample output is:

Welcome to Johnny's Resturant
1: Plain Egg \$1.45
2: Bacon and Egg \$2.45
3: Muffin \$0.99
4: French Toast \$1.99
6: Cereal \$0.69
7: Coffee \$0.50
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 number: 1

Select another item Y/y (Yes), N/n (No): Y

Enter item number: 2

Select another item Y/y (Yes), N/n (No): N

Welcome to Johnny's Resturant
Plain Egg \$1.45
Bacon and Egg \$2.45
Tax \$0.20
Amount Due \$4.10
Format your output with two decimal places. The name of each item in the output must be left justified. You may assume that the user selects only one item of a particular type.

The main part I am havig trouble with is in this section of the coding here

while(ordering || choice == 'Y' || choice == 'y')
{
cout << "Do you want to make selection Y/y (Yes), N/n (No): " << endl;
cin >> choice;
cout << "Enter item number" << endl;
cin >> orderChoice;
do
{
if (orderChoice > 0 && orderChoice <= menuItems)
{
cout << "Select another item Y/y (Yes), N/n (No): " << endl;
cin >> choice1;
cout << "Enter item number" << endl;
cin >> orderChoice;
}
else
ordering = false;
}
while (orderChoice > 0 && orderChoice <= menuItems && choice1 == 'Y' && choice1 == 'y');

cin.ignore(2);
return 0;
}
)
If I take out the do while the program kinda works right if I say Y/y it asks for the number if I enter a number it asks the message again. however if I say N/n or hit 0 it still prompts the next message and I have to hit 0 two times for it to go to the rest of the code. with the statement in the coding like now I get an error message saying a function is not allowed before all of my Void sections. I have been stuck for a few days and my assignment is due on Monday. Can someone please show me what I have done wrong and how to fix it.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136`` ``````#include #include #include #include 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; char choice1; getData(menuList); showMenu(menuList, menuItems); while(ordering || choice == 'Y' || choice == 'y') { cout << "Do you want to make selection Y/y (Yes), N/n (No): " << endl; cin >> choice; cout << "Enter item number" << endl; cin >> orderChoice; do { if (orderChoice > 0 && orderChoice <= menuItems) { menuOrder[orderChoice - 1] += 1; cout << "Select another item Y/y (Yes), N/n (No): " << endl; cin >> choice1; cout << "Enter item number" << endl; cin >> orderChoice; } else ordering = false; } while (orderChoice > 0 && orderChoice <= menuItems && choice1 == 'Y' && choice1 == 'y'); 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 << "You can make up to 8 single order selections" << 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 << "Thanks for eating at Johnny's" << "Customer check: " << 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 << setw(14) << left << "Tax" << checkTax << endl << setw(14) << left << "Total" << checkTotal << endl; }``````

Last edited on
@XzainKarrito,
 PLEASE USE CODE TAGS (the <> formatting button to the right), when posting code! Along with the proper indenting, it makes it easier to read your code, and thus also easier to respond to your post. Tutorials on how to use code tags: http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/ I've found the second link to be the most help. Hint: You can hit "edit post", highlight your code and then press the <> formatting button. Note: This will not automatically indent your code! That part is up to you! I've found it's easiest to copy and paste pre-indented code directly from the IDE, that way it is already properly formatted. You can use the "preview" button at the bottom to see how it looks.
Using Code Tags, @Handy Andy, from cplusplus.com

Additionally, what errors are you getting exactly? If I know exactly what errors you're getting, it will be easier to help you.
Thanks!
max
Last edited on
the errors I get are these

main.cpp: In function ‘int main()’:
main.cpp:63:3: error: a function-definition is not allowed here before ‘{’ token
{
^
main.cpp:103:3: error: a function-definition is not allowed here before ‘{’ token
{
^
main.cpp:118:3: error: a function-definition is not allowed here before ‘{’ token
{
^
main.cpp:136:3: error: expected ‘}’ at end of input
}
^
/bin/bash: line 4: ./a.out: No such file or directory
It appears that you are missing a closing brace for main(). Remember that you can't implement a function inside another function.

If your indentation was a little more consistent you would probably be able to see the problem easier:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136`` ``````#include #include #include #include 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; char choice1; getData(menuList); showMenu(menuList, menuItems); while(ordering || choice == 'Y' || choice == 'y') { cout << "Do you want to make selection Y/y (Yes), N/n (No): " << endl; cin >> choice; cout << "Enter item number" << endl; cin >> orderChoice; do { if(orderChoice > 0 && orderChoice <= menuItems) { menuOrder[orderChoice - 1] += 1; cout << "Select another item Y/y (Yes), N/n (No): " << endl; cin >> choice1; cout << "Enter item number" << endl; cin >> orderChoice; } else ordering = false; } while(orderChoice > 0 && orderChoice <= menuItems && choice1 == 'Y' && choice1 == 'y'); 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 << "You can make up to 8 single order selections" << 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 << "Thanks for eating at Johnny's" << "Customer check: " << 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 << setw(14) << left << "Tax" << checkTax << endl << setw(14) << left << "Total" << checkTotal << endl; } ``````
@XzainKarrito,
 /bin/bash: line 4: ./a.out: No such file or directory

Check to make sure you are in the correct directory.

Enter "ls" to list everything in your current dir, and if you don't see a.out listed in the directory, then you're in the wrong one.

Either that or it doesn't exist, in which case you'll have to compile it and try again. What compiler are you using?

By the way, thank you for editing your post and posting your errors! :)
Last edited on
Not sure which compiler it is. I am using MindTap by Cengage to do all the assignments and it has a compiler for the labs but I am guessing Sandbox. I have the fixed bracket but still get the same errors. I still am not sure how to use the coding to get the results I am looking for seeing as I can't use a function within another function.
Last edited on
I know that this is where in my code that I have the issue I just don't know how to fix it.

 ``1234567891011121314151617181920212223242526`` `````` showMenu(menuList, menuItems); while(ordering || choice == 'Y' || choice == 'y') { cout << "Do you want to make selection Y/y (Yes), N/n (No): " << endl; cin >> choice; cout << "Enter item number" << endl; cin >> orderChoice; do { if(orderChoice > 0 && orderChoice <= menuItems) { menuOrder[orderChoice - 1] += 1; cout << "Select another item Y/y (Yes), N/n (No): " << endl; cin >> choice1; cout << "Enter item number" << endl; cin >> orderChoice; } else ordering = false; } while(orderChoice > 0 && orderChoice <= menuItems && choice1 == 'Y' && choice1 == 'y'); printCheck(menuList, menuOrder, menuItems); cin.ignore(2); return 0; } ``````
jib indented it according to the braces.

Notice how the functions from line 61 are NOT in the left column.
This means your main is missing a closing brace.

So put a } on line 57.

Also, the return 0; means your outer while loop is not going to loop at all.
 ./a.out: No such file or directory

That happened because the program didn't compile ....

 I have the fixed bracket but still get the same errors.

Can't have fixed the bracket. By the way, it is a brace not a bracket. <> are angle brackets. [] are square brackets

 I still am not sure how to use the coding to get the results I am looking for seeing as I can't use a function within another function.

It is only because you had functions defined inside the main function. You are on the right track, just need to put the closing brace in the correct place - hint at the end of the main function.

Your IDE should automatically do braces for you. The old school way of doing the same thing: Type both the opening and closing brace, then go back and fill in what is inside the braces. That way you will never have a mismatching brace, parentheses or anything else that comes in pairs.

Consider using a `switch` statement instead of a whole of of convoluted logic to get what you want. Also, with the `choice` variable, convert it to uppercase to halve any logic that you have.
@XzainKarrito,
Consider using toupper() instead of this:
 `` `` ``while (ordering || choice == 'Y' || choice == 'y')``

You will need to #include <cctype>

It would look like:
 `` `` ``while (ordering || toupper (choice) == 'Y')``

Just a bit shorter code.
So I have made a lot of changes and now I get the menu but when I say no it goes through the questions again before printing the final report. Not sure what I did to get it to do it twice like that.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168`` ``````#include #include #include #include #include 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; char choice1; getData(menuList); showMenu(menuList, menuItems); while(ordering || toupper (choice) == 'Y') { cout << "Do you want to make selection Y/y (Yes), N/n (No): " << endl; cin >> choice; switch(choice) { case 'y': cout << "Enter item number" << endl; cin >> orderChoice; break; case 'Y': cout << "Enter item number" << endl; cin >> orderChoice; case 'n': ordering = false; break; case 'N': ordering = false; break; } if(orderChoice > 0 && orderChoice <= menuItems) { menuOrder[orderChoice - 1] += 1; cout << "Select another item Y/y (Yes), N/n (No): " << endl; cin >> choice1; switch(choice1) { case 'Y': cout << "Enter item number" << endl; cin >> orderChoice; menuOrder[orderChoice - 1] += 1; break; case 'y': cout << "Enter item number" << endl; cin >> orderChoice; menuOrder[orderChoice - 1] += 1; break; case 'N': ordering = false; break; case 'n': ordering = false; break; } } else ordering = false; } 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 << "You can make up to 8 single order selections" << 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 << "Thanks for eating at Johnny's" << "Customer check: " << 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 << setw(14) << left << "Tax" << checkTax << endl << setw(14) << left << "Total" << checkTotal << endl; } ``````

This is what it shows:
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
[ 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
Select another item Y/y (Yes), N/n (No):
y
Enter item number
2
Do you want to make selection Y/y (Yes), N/n (No):
n
Select another item Y/y (Yes), N/n (No):
n
Thanks for eating at Johnny'sCustomer check:
Plain Egg \$1.45
Bacon and Egg\$4.9
Tax 0.318
Total 6.67

Last edited on
Okay I fixed the last issue sort of but now it doesn't go to the next question of select another item:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171`` ``````#include #include #include #include #include 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; char choice1; getData(menuList); showMenu(menuList, menuItems); while(ordering || toupper (choice) == 'Y') { cout << "Do you want to make selection Y/y (Yes), N/n (No): " << endl; cin >> choice; switch(choice) { case 'y': cout << "Enter item number" << endl; cin >> orderChoice; menuOrder[orderChoice - 1] += 1; break; case 'Y': cout << "Enter item number" << endl; cin >> orderChoice; menuOrder[orderChoice - 1] += 1; case 'n': ordering = false; break; case 'N': ordering = false; break; } if(orderChoice > 0 && orderChoice <= menuItems && toupper (choice) == 'y') { menuOrder[orderChoice - 1] += 1; cout << "Select another item Y/y (Yes), N/n (No): " << endl; cin >> choice1; switch(choice1) { case 'Y': cout << "Enter item number" << endl; cin >> orderChoice; menuOrder[orderChoice - 1] += 1; break; case 'y': cout << "Enter item number" << endl; cin >> orderChoice; menuOrder[orderChoice - 1] += 1; break; case 'N': ordering = false; break; case 'n': ordering = false; break; } } else ordering = false; } 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 << "You can make up to 8 single order selections" << 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 << "Thanks for eating at Johnny's" << "Customer check: " << 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 << setw(14) << left << "Tax" << checkTax << endl << setw(14) << left << "Total" << checkTotal << endl; } ``````

This is what it shows:

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
[ 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):
n
Thanks for eating at Johnny'sCustomer check:
Plain Egg \$1.45
Bacon and Egg\$2.45
Tax 0.195
Total 4.1
Here is my "standard school assignment reply"

A code without ANY comments should be only done when your job security would be "jeopardized."

Most IDE , not compilers / linkers , let you "beautify" your code AKA ":fix" indentation and SOMETIME it will show the mismatched "brackets".

And yes, sometime the errors are not what you expect - but originally missing closing brackets in main
still pointed to source of the problem.

Analyzing errors gets easier with experience - in your initial problem your IDE MAY have the "feature" to identify bracketed blocks of code - ask your teacher.

As far as code not doing expected - learn how to set breakpoints and step thru you code till you find the issue.

Primarily my teacher hasn't talked to any of us this whole semester due to it being an online only distance class all the assignments are on Mindtap Cengage. I have asked a tutor for help and they helped me get to the point I was at when I started this post. I am completely new to C++ and am trying to learn. So I came on here hoping to find knowledgeable people to help me learn what I am messing up and not give me the answer without an explanation. The people that have posted so far have helped me learn some things I didn't know and the "Bracket was there originally I accidentally deleted it when I was trying to figure out what I was messing up before finding my area that I was having a problem at. I have set breakpoints I just don't see what I am doing wrong and am seeking advice and help as to what errors I am making, why it is doing what it is doing, and how I could go about fixing it. Thank you for your response though.
> if(orderChoice > 0 && orderChoice <= menuItems && toupper (choice) == 'y')
Your toupper is comparing with a lowercase.

You can simplify your cases like this.
 ``123456789101112`` `````` switch (choice) { case 'y': case 'Y': cout << "Enter item number" << endl; cin >> orderChoice; menuOrder[orderChoice - 1] += 1; break; case 'n': case 'N': ordering = false; break; }``````
 I am completely new to C++ and am trying to learn.

There are two online tutorials you might want to look at.

1. The tutorial here at CPlusPlus. It is outdated, no C++14 or later.
http://www.cplusplus.com/doc/tutorial/

2. Learn C++. It is getting updated frequently.
https://www.learncpp.com/
Here's a version of what you have so far with a few things changed:
1. Most of what you have is fairly good but is clearer just by using some meaningful names for things.
2. I've indicated the main program changes and see if it suits what you are trying to do. There was a lot of duplication and unnecessary stuff.
3. You need to revisit the getData function. All you have is an array of structs without all those lines and variable names. Just populate the array as you would if the items were ints.
4. Of course, I haven't verified this as much as you will need to do. It looks to me though like it works.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135`` ``````#include #include #include #include #include using namespace std; // struct for menu item struct Item { string name; double price; }; void getData(Item[], int); void showMenu(Item[], int ); void printCheck(Item[], int[], int); int main() { const int NO_ITEMS = 8; Item menu[NO_ITEMS]; int order[NO_ITEMS] = {0}; int orderChoice = 0; bool ordering = true; char choice{'Y'}; // <-- getData(menu, NO_ITEMS); showMenu(menu, NO_ITEMS); while( ordering ) // <-- { cout << "Do you want to make selection Y/y (Yes), N/n (No): " << endl; cin >> choice; switch(toupper(choice)) // <-- { case 'Y': cout << "Enter item number" << endl; cin >> orderChoice; order[orderChoice - 1] = 1; // <-- // EDIT was off by one break; case 'N': ordering = false; break; default: cout << "Wrong answer\n"; } } // <-- printCheck(menu, order, NO_ITEMS); return 0; } void getData(Item menuList[], int no_items ) { // A HORRIBLY HARD WAY TO DO THIS :[ Item plainEgg; Item baconEgg; Item muffin; Item frenchToast; Item fruitBasket; Item cereal; Item coffee; Item tea; plainEgg.name = "Plain Egg"; plainEgg.price = 1.45; baconEgg.name = "Bacon and Egg"; baconEgg.price = 2.45; muffin.name = "Muffin"; muffin.price = 0.99; frenchToast.name = "French Toast"; frenchToast.price = 1.99; fruitBasket.name = "Fruit Basket"; fruitBasket.price = 2.49; cereal.name = "Cereal"; cereal.price = 0.69; coffee.name = "Coffee"; coffee.price = 0.50; tea.name = "Tea"; tea.price = 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(Item menuList[], int x) { int count; cout << "Welcome to Johnny's Resturant" << endl; cout << "You can make up to 8 single order selections" << endl; for(count = 0; count < x; count++) { cout << setw(2) << left << "[" << count + 1 << "]" << menuList[count].name << '\$' << menuList[count].price << endl; } } void printCheck(Item menuList[], int menuOrder[], int menuItems) { double checkTotal = 0; double checkTax = 0; const double TAX = .05; cout << "Thanks for eating at Johnny's" << "Customer check: " << endl; for(int i = 0; i < menuItems; i++) { if(menuOrder[i] > 0) { cout << setprecision(3) << setw(10) << left << menuList[i].name << '\$' << (menuList[i].price * menuOrder[i]) << endl; checkTotal += (menuList[i].price * menuOrder[i]); } } checkTax = checkTotal * TAX; checkTotal += checkTax; cout << setw(14) << left << "Tax" << checkTax << endl << setw(14) << left << "Total" << checkTotal << endl; }``````

 ```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: Bacon and Egg\$2.45 Muffin \$0.99 French Toast\$1.99 Tax 0.272 Total 5.7 Program ended with exit code: 0```

Last edited on
One could have a switch with the cases being of type char, with 1 to 8, and a 'q' to quit. That way one doesn't have to ask Yes / No each time. The 'q' option works the same way as the 'N' option at the moment.

A better way to do the Items, perhaps what againtry was hinting at:

Provide a constructor for the Item struct, that sets both name and price values;
And to demonstrate those two possibilities:
 ``12345678910111213141516`` ``````vector vec_item { {"Plain Egg", 1.45}, {"Bacon and Egg", 2.45}, {"Muffin", 0.99}, {"French Toast", 1.99}, {"Fruit Basket", 2.49}, {"Cereal", 0.69}, {"Coffee", 0.50}, {"Tea", 0.75} }; for( auto i: vec_item) { cout << i.name << ' ' << i.price << '\n'; }``````

 ``123456789101112131415161718`` `````` Item list[] = { {"Plain Egg", 1.45}, {"Bacon and Egg", 2.45}, {"Muffin", 0.99}, {"French Toast", 1.99}, {"Fruit Basket", 2.49}, {"Cereal", 0.69}, {"Coffee", 0.50}, {"Tea", 0.75} }; for(int i = 0; i < no_items; i++) { menu[i] = list[i]; } return;``````

PS the vector requires a few changes to how the struct/constructor works.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111`` ``````#include #include #include using namespace std; // struct for menu item struct Item { string name; double price; }; void getData(Item[], int); void showMenu(Item[], int ); void printCheck(Item[], int[], int); int main() { const int NO_ITEMS = 8; Item menu[NO_ITEMS]; int order[NO_ITEMS] = {0}; int choice{0}; getData(menu, NO_ITEMS); showMenu(menu, NO_ITEMS); while( cout << "Enter selection 1-8 any alpha for the Bill " && cin >> choice && choice != 0 ) { switch( choice ) { case 1 ... 8: order[choice - 1] = 1; break; default: cout << "Wrong answer\n"; break; } } printCheck(menu, order, NO_ITEMS); return 0; } void getData(Item menu[], int no_items ) { Item list[] = { {"Plain Egg", 1.45}, {"Bacon and Egg", 2.45}, {"Muffin", 0.99}, {"French Toast", 1.99}, {"Fruit Basket", 2.49}, {"Cereal", 0.69}, {"Coffee", 0.50}, {"Tea", 0.75} }; for(int i = 0; i < no_items; i++) { menu[i] = list[i]; } return; } void showMenu(Item menuList[], int x) { int count; cout << " Welcome to Johnny's Resturant\n"; cout << "You can make up to 8 single order selections\n\n"; for(count = 0; count < x; count++) { cout << setw(11) << "[" << count + 1 << "] " << setw(14)<< menuList[count].name << fixed << setprecision(2)<< " \$" << menuList[count].price << '\n'; } cout << '\n'; } void printCheck(Item menuList[], int menuOrder[], int menuItems) { double checkTotal = 0; double checkTax = 0; const double TAX = .05; cout << "Thanks for eating at Johnny's\n" << "Customer check: " << endl; for(int i = 0; i < menuItems; i++) { if(menuOrder[i] > 0) { cout << setprecision(3) << setw(10) << left << menuList[i].name << '\$' << (menuList[i].price * menuOrder[i]) << endl; checkTotal += (menuList[i].price * menuOrder[i]); } } checkTax = checkTotal * TAX; checkTotal += checkTax; cout << setw(14) << left << "Tax" << checkTax << endl << setw(14) << left << "Total" << checkTotal << endl; }``````

 ``` 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.50 [8] Tea \$0.75 Enter selection 1-8 any alpha for the Bill 2 Enter selection 1-8 any alpha for the Bill 3 Enter selection 1-8 any alpha for the Bill y Thanks for eating at Johnny's Customer check: Bacon and Egg\$2.450 Muffin \$0.990 Tax 0.172 Total 3.612 Program ended with exit code: 0```
Pages: 12