Everything works except the total comes out with some weird number and throws everything else off..
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
struct menuItemType
{
string menuItem;
double menuPrice;
bool selected;
};
void getData(menuItemType menuItems[8], ifstream& infile) ;
void showMenu(int& choice, menuItemType menuItems[8]);
void printCheck( menuItemType menuItems[8] , int& total);
int main()
{
std::cout << std::setprecision(2);
ifstream infile ;
infile.open("Menu.txt") ;
int choice=0 ;
int total=0;
menuItemType menuItems[8];
getData(menuItems, infile) ;
showMenu(choice,menuItems) ;
printCheck(menuItems, total) ;
return 0;
}
void getData(menuItemType menuItems[8], ifstream& infile)
{
int item= 0;
do{
getline(infile, menuItems[item].menuItem);
infile >> menuItems[item].menuPrice;
infile.get();
menuItems[item].selected= false ;
item++;
}while(infile);
}
void showMenu(int& choice, menuItemType menuItems[8])
{
cout << "Enter the number of your selections until you are finished" << endl;
cout << "0 - Plain Egg" << setw(14) << "$1.45" << endl;
cout << "1 - Bacon and Egg" << setw(10) << "$2.45" << endl;
cout << "2 - Muffin" << setw(17) << "$0.99" << endl;
cout << "3 - French Toast" << setw(11) << "$1.99" << endl;
cout << "4 - Fruit Basket" << setw(11) << "$2.49" << endl;
cout << "5 - Cereal" << setw(17) << "$0.69" << endl;
cout << "6 - Coffee" << setw(17) << "$0.50" << endl;
cout << "7 - Tea" << setw(21) << "$0.75" << endl;
cout << "8- Finished Ordering- Print Check" << endl;
do{
cin >> choice ;
menuItems[choice].selected = true ;
}while (choice != 8) ;
}
void printCheck( menuItemType menuItems[8], int& total)
{
int c = 0;
int k = 0;
double Total = 0.0;
double Tax = 0.05;
double AmountDue = 0.0;
for (c=0; c<8; c++)
{
if (menuItems[k].selected == true)
{
Total = Total + menuItems[k].menuPrice;
}
k++;
}
Tax = Tax * Total;
AmountDue =( Tax * Total) + Total;
cout << "\nWelcome to Jason's Restaurant" << endl;
cout << "Total - " << " " << Total << endl;
cout << "Tax - " << " " << Tax << setw(5) << endl;
cout << "Amount Due - " << " " << AmountDue << setw(10) << endl;
}
Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
void printCheck( menuItemType menuItems[8], int& total)
{
int c = 0;
int k = 0;
double Total = 0.0;
double Tax = 0.05;
double AmountDue = 0.0;
for (c=0; c<8; c++)
{
if (menuItems[k].selected == true) /// change k to c
{
Total = Total + menuItems[k].menuPrice; //change k to c
}
//k++; /// remove
}
Tax = Tax * Total;
AmountDue =( Tax * Total) + Total; /// change this line to AmountDue =Tax + Total;
cout << "\nWelcome to Jason's Restaurant" << endl;
cout << "Total - " << " " << Total << endl;
cout << "Tax - " << " " << Tax << setw(5) << endl;
cout << "Amount Due - " << " " << AmountDue << setw(10) << endl;
}
|
Last edited on