Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C + + code I did the code myself, I ' m just stuck. The code reads in from a file called MenuData.txt ( from
C code
I did the code myself, Im just stuck.
The code reads in from a file called MenuData.txt from notepad with this info, in this format:
PlainEgg
BaconandEgg
Muffin
FrenchToast
FruitBasket
Cereal
Coffee
Tea
Then I use the data from the imported file for an array. I output the menu to the console from the array and prompt the user to select an item from the menu. They can choose up to times item per choice Then I calculate the sales tax. The very last step is to output the receipt with the items selected, the tax, total cost, and amount due.
The file reads fine, but the issue Im having is I somehow created an infinite loop and the tax and total amount aren't printing to the receipt. Please help!!
I'll include an image to give an idea of what the output should look like. Thank you!
Please don't include advanced stuff like stringstream, we haven't learned that!
This is the code:
#include fstream
#include iostream
#include iomanip
#include cstring
using namespace std;
const int MAXITEMS ; Maximum number of menu items
Struct for menu items
struct menuItemType
char itemName; Name of the item
double itemPrice; Price of the item
;
Function to load data from file into menuList array
void getDatamenuItemType menuList int& itemCount
ifstream infile;
infile.openMenuDatatxt;
int i ;
using if else statement for if file opens successfully or not
ifinfile.isopen
cout "File can't be opened" endl;
else
whileinfile.eof
storing player information in the array players
infile menuListitemCountitemName;
infile menuListitemCountitemPrice;
itemCount;
infile.close;
Function to show the menu
void showMenumenuItemType menuList int itemCount
cout "Welcome to My Restaurant" endl;
cout Today's Menu endl;
cout endl;
for int i ; i itemCount; i
cout i : menuListiitemName ;
cout fixed showpoint setprecision$ menuListiitemPrice endl;
cout
You can make up to itemCount single order selections" endl;
Function to calculate and print the check
void printCheckconst menuItemType menuList const bool selectedItem
double total ;
cout
Your order
;
for int i ; i MAXITEMS; i
if selectedItemi
cout left setw menuListiitemName $ fixed setprecision
menuListiitemPrice endl;
total menuListiitemPrice;
while choice Y choice y;
Print the check
printCheckmenuList selectedItem;
calculating tax
double tax total ;
total tax;
outputting the tax and amount due
cout "Tax $ fixed showpoint setprecision tax endl;
cout "Amount Due $ fixed showpoint setprecision total endl;
int main
menuItemType menuListMAXITEMS;
int itemCount;
getDatamenuList itemCount;
showMenumenuList itemCount;
User selection
bool selectedItemMAXITEMSfalse;
char choice;
int selection;
do
cout Do you want to make selection Yy Yes Nn No: ;
cin choice;
if choice Y choice y
cout "Enter item number: ;
cin selection;
if selection && selection itemCount
if selection MAXITEMS
cout "You reached the menu ordering selection limit endl;
break;
else
selectedItemselection true;
selection;
cout "selected:" menuListselection itemName endl;
else
cout "Invalid item number. Please try again." endl;
while choice Y choice y;
Print the check
printCheckmenuList selectedItem;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started