I am having a problem getting a certain part of my program to loop. I need the loop to repeat if 'Y' or 'y' is picked after a menu item is chosen. And if 'N' or "n" is picked print the receipt. I have tried numerous times to get the loop correct, but cannot figure it out. Any help would be beneficial. Also, I can now get the amount due to calculate but it does not seem to add the tax right, it adds extra after tax is calculated.
#include <iostream>
#include <string>
#include <iomanip>
void showMenu();
using namespace std;
const int menu = 1;
struct menuItemType
{
string menuItem;
double menuPrice;
};
void getData(menuItemType placeorder[8]);
void printCheck(menuItemType printorder[]);
int main()
{
cout <<"Welcome to Johnny's Restaurant"<< endl;
cout <<"----Today's Menu----"<< endl;
showMenu();
cout << endl;
cout << "You can make up to 8 single order selections"<<endl;
cout << "Do you want to make a selection Y/y (Yes). N/n (No): ";
char selection;
cin >> selection;
if (selection == 'Y' || selection == 'y')
{
menuItemType menuList[8];
menuItemType order[8];
getData(order);
printCheck(order);
}
system("PAUSE");
return 0;
}
void showMenu()
{
cout << "1: Plain Egg.................$ 1.45" << endl;
cout << "2: Bacon and Egg.............$ 2.45" << endl;
cout << "3: Muffin....................$ 0.99" << endl;
cout << "4: French Toast..............$ 1.99" << endl;
cout << "5: Fruit Basket..............$ 2.49" << endl;
cout << "6: Cereal....................$ 0.69" << endl;
cout << "7: Coffee....................$ 0.50" << endl;
cout << "8: Tea.......................$ 0.75" << endl;
}
// puts data into the array
void getData(menuItemType placeorder[8])
{
menuItemType menuList[8];
menuList[0].menuItem = "Plain Egg ";
menuList[1].menuItem = "Bacon and Egg ";
menuList[2].menuItem = "Muffin ";
menuList[3].menuItem = "French Toast ";
menuList[4].menuItem = "Fruit Basket ";
menuList[5].menuItem = "Cereal ";
menuList[6].menuItem = "Coffee ";
menuList[7].menuItem = "Tea ";
menuList[0].menuPrice = 1.45;
menuList[1].menuPrice = 2.45;
menuList[2].menuPrice = 0.99;
menuList[3].menuPrice = 1.99;
menuList[4].menuPrice = 2.49;
menuList[5].menuPrice = 0.69;
menuList[6].menuPrice = 0.50;
menuList[7].menuPrice = 0.75;
cout << endl;
for (int x=0; x<8; x++)
{
cout << " " << endl;
int answer;
cout << "Enter item number: ";
cin >> answer;
cout << "Select another item Y/y (Yes), N/n (No): ";
char selectionTwo;
cin >> selectionTwo;
if (selectionTwo == 'N' || selectionTwo == 'n')
{
}
placeorder[x].menuItem = menuList[answer-1].menuItem;
placeorder[x].menuPrice = menuList[answer-1].menuPrice;
}
}
// calculates and prints the RECEIPT
void printCheck(menuItemType printorder[])
{
const double taxRate = 0.05;
int x = 0;
double amtDue = 0;
double tax = 0;
cout << endl;
cout << endl;
cout << endl;
cout << "Welcome to Johnny's Restaurant" << endl;
cout << endl;
for (x=0; x<8; x++)
{
cout.precision(3);
cout << showpoint;
tax += (printorder[x].menuPrice) * taxRate;
cout << printorder[x].menuItem << setw(13) << "$ " << printorder[x].menuPrice << endl;
amtDue += (printorder[x].menuPrice) + tax;
}
cout.precision(2);
cout << showpoint;
cout<<"Tax $ " << tax << endl;
cout.precision(3);
cout << showpoint;
cout<<"Amount Due $ " << amtDue << endl;
}