My code is working almost the way I need it to. However, when I run the program I am getting this
Welcome to Johnny's Restaurant
Bacon and Egg $2.45
Muffin $1.98
Coffee $0.50
Tax $0.25
Amount Due $5.18
When I want to get this:
Welcome to Johnny's Restaurant
1 Bacon and Egg $2.45
2 Muffin $1.98
1 Coffee $0.50
Tax $0.25
Amount Due $5.18
Also, this is my last project this year so any stylistic suggestions are appreciated, thanks in advance
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const double tax = .05;
const int menuItems = 8;
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()
{
menuItemType menuList[menuItems];
int menuOrder[menuItems] = {0};
int orderChoice = 0;
bool ordering = true;
int count = 0;
getData(menuList);
showMenu(menuList, menuItems);
while(ordering)
{
cout << "\nPlease enter the number for your desired selection\n"
<< "or enter 0 to complete your order: ";
cin >> orderChoice;
if (orderChoice > 0 && orderChoice <= menuItems)
{
menuOrder[orderChoice -1] += 1;
}
else
ordering = false;
}
printCheck(menuList, menuOrder, menuItems);
return 0;
}
void getData(menuItemType menuList[])
{
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[], int x)
{
int count;
cout << "Welcome to Johnny's Restaurant!!!" << endl;
cout << "What would you like to order?" << endl;
cout << fixed << showpoint << setprecision(2);
for(count = 0; count < x; count ++)
{
cout << setw(2) << left << count + 1
<< setw(16) << menuList[count].menuItem << '$'
<< menuList[count].menuPrice << endl;
}
}
void printCheck(menuItemType menuList[], int menuOrder[], int menuItems)
{
double checkTotal = 0;
double checkTax = 0;
cout << "\nThank You for Eating at Johnny's!!!\n"
<< "Customer Check: " << endl;
for(int i = 0; i < menuItems; i++)
{
if(menuOrder[i] > 0)
{
cout << setprecision(2) << setw(16) << left << menuList[i].menuItem
<< '$' << (menuList[i].menuPrice * menuOrder[i]) << endl;
checkTotal += (menuList[i].menuPrice * menuOrder[i]);
}
}
checkTax = checkTotal * tax;
checkTotal += checkTax;
cout << setw(16) << left << "Tax" << '$' << checkTax << endl;
cout << setw(16) << left << "Total" << '$' << checkTotal << endl;
}