c++ My code seems to run fine, my total amount due and tax displays correct. my problem is the dollar amount output reads as not in the correct format? for example Tax $0.20 Amount Due $4.18 the amount underlined says it is not displayed correctly, but im assuing its something to do with the code for the showing of the dollar amount? the number of dollar amount is correct, but still reads as wrong? HERE IS THE CODE //include the required header fields #include #include #include using namespace std; //create a structure menuItemType struct menuItemType { //declare the components of the structure string menuItem; double menuPrice; }; //declare the function prototype void getData(menuItemType menuList[]); void showMenu(menuItemType menuList[],int n); void printCheck(menuItemType menuList[], int menu_order[],int n); //definition of the main function int main() { //declare the required variables const int item = 8; menuItemType menuList[item]; int menu_order[item] = {0}; int choice = 0; bool order = true; //call the function getData() getData(menuList); //call the function showMenu() showMenu(menuList, item); //while the order is true continue doing this while loop while(order) { cout<<"Enter the number of the item you wish to order."<>choice; if (choice > 0&&choice<=item) { menu_order[choice - 1] +=1; } else { order = false; } } //call the function() printCheck printCheck(menuList,menu_order,item); return 0; } //end of the main func //definition of the function getData() void getData(menuItemType menuList[]) { //set the menu as given in the question 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; } //definition of the function showMenu() void showMenu(menuItemType menuList[], int n) { //declare the required varaible int count; //prompt user to view menu cout<<"Johnny's Restaurant Menu"<0) { cout <
c++
My code seems to run fine, my total amount due and tax displays correct. my problem is the dollar amount output reads as not in the correct format?
for example
Tax $0.20
Amount Due $4.18
the amount underlined says it is not displayed correctly, but im assuing its something to do with the code for the showing of the dollar amount?
the number of dollar amount is correct, but still reads as wrong?
HERE IS THE CODE
//include the required header fields
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//create a structure menuItemType
struct menuItemType
{
//declare the components of the structure
string menuItem;
double menuPrice;
};
//declare the function prototype
void getData(menuItemType menuList[]);
void showMenu(menuItemType menuList[],int n);
void printCheck(menuItemType menuList[], int menu_order[],int n);
//definition of the main function
int main()
{
//declare the required variables
const int item = 8;
menuItemType menuList[item];
int menu_order[item] = {0};
int choice = 0;
bool order = true;
//call the function getData()
getData(menuList);
//call the function showMenu()
showMenu(menuList, item);
//while the order is true continue doing this while loop
while(order)
{
cout<<"Enter the number of the item you wish to order."<<endl;
//get input from user
cin>>choice;
if (choice > 0&&choice<=item)
{
menu_order[choice - 1] +=1;
}
else
{
order = false;
}
}
//call the function() printCheck
printCheck(menuList,menu_order,item);
return 0;
}
//end of the main func
//definition of the function getData()
void getData(menuItemType menuList[])
{
//set the menu as given in the question
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;
}
//definition of the function showMenu()
void showMenu(menuItemType menuList[], int n)
{
//declare the required varaible
int count;
//prompt user to view menu
cout<<"Johnny's Restaurant Menu"<<endl;
cout<<endl;
for(count = 0; count < n; count++)
{
cout << setw(2)<< left << count + 1 <<setw(20)<<left
<<menuList[count].menuItem<<'$'<<
menuList[count].menuPrice<<endl;
}
}
//definition of the function printCheck()
void printCheck(menuItemType menuList[],int menuOrder[], int n)
{
//declare the required variables
double Bill = 0;
double calculated_Tax = 0;
const double TAX = .05;
cout<<"Welcome to Johnny's Restaurant" <<endl;
for (int i = 0; i < n; i++)
{
if(menuOrder[i]>0)
{
cout <<fixed<<setprecision(2) <<setw(20)<<left<<menuList[i].menuItem<<'$'<<(menuList[i].menuPrice * menuOrder[i]) << endl;
Bill += (menuList[i].menuPrice * menuOrder[i]);
}
}
//calculate the total bill amount and the tax
calculated_Tax = Bill*TAX;
Bill +=calculated_Tax;
//print the bill for the user
cout <<setw(20) <<left << "Tax" <<"$"<<fixed<<setprecision(2)<<calculated_Tax<<endl
<<setw(20)<<left<<"Amount Due"<<"$"<<Bill<<endl;
}
Step by step
Solved in 3 steps with 1 images