Can Anyone Find my mistake?
Nov 26, 2012 at 5:14am UTC
My program is supposed to read in a file that has a breakfest menu including foods like eggs and bacon. The user can select as much as many items as theyd like but can only select them once.
I then I have to provide a receipt include the items that were purchased, sales tax and then total owed. This is where Im having a problem. My math works, but Im having trouble properly bringing my items in that I have selected and properly producing the receipt.
I provided my whole code below instead of just the receipt function incase someone notices anywhere else I screwed up.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
struct menuItemType
{
string itemName;
double itemCost;
};
void getData(menuItemType menu[]);
void showMenu(menuItemType menu[]);
void printCheck(menuItemType menu[]);
int main()
{
cout<< " Welcome to Our Diner! " << endl;
cout<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout<< " *To select an Item from the list below, " << endl;
cout<< "just indicate the Item number for the item \n\n" << endl;
menuItemType menu [8];
getData(menu);
showMenu(menu);
return 0;
}
void getData(menuItemType item[])
{
int i=0;
ifstream inData;
inData.open("InMenu.txt" );
cout << fixed << setprecision(2);
while (!inData.eof())
{
inData >> item[i].itemName >> item[i].itemCost;
++i;
}
}
void showMenu(menuItemType item[])
{
int choice = 0, quantity = 0;
char exit = 'y' ;
int j = 0, z = 1, i = 1;
for (int i=0; i<8; i++)
{
cout << j << ". " << setw(18) << left << item[i].itemName << "$" << setw(10) << item[i].itemCost << endl;
j++;
}
cout << endl;
while (exit == 'y' || exit == 'Y' )
{
cout << "Please Enter Item number of your Selection " << endl;
cin >> choice;
if (cin.fail())
{
cout << "~~~~~~~ Selection Not Valid ~~~~~~~" << endl;
cin.clear();
cin.ignore(1000,'\n' );
}
else if (choice==0) {break ; }
}
void printCheck(menuItemType menu[]);
{
double Total = 0;
double billTotal = 0;
double billTax = 0;
const double Tax= .05;
cout << "\n\nThank you for chosing Josh's Diner!\n" << endl;
cout << "Your Receipt:\n" << endl;
for (int i = 0; i <choice ; i++)
{
cout << setprecision(2) << setw(18) << left << item[i].itemName
<< '$' << item[i].itemCost << endl;
Total += item[i].itemCost;
}
billTax = Total * Tax;
billTotal = Total + billTax;
cout << setw(14) << left << "Tax $" << billTax << endl;
cout << "____________________________________________" << endl;
cout << setw(14) << left << "Total Due $" << billTotal << endl;
}
}
Last edited on Nov 27, 2012 at 6:13am UTC
Nov 26, 2012 at 5:53am UTC
Function printCheck is never called.
Nov 26, 2012 at 6:11am UTC
Thanks for the reply!
Would you mind explaining to me as to how to properly call printCheck so that I can get my receipt to look something like this:
Sales Receipt
1 Bacon and Egg $2.45
1 Coffee $0.50
-----
$2.95
Tax 0.14
-----
Total $3.09
Nov 26, 2012 at 6:27am UTC
I meant that the function was not called in main().
The parameter menu[] is not used in the function, either.
HTH
Topic archived. No new replies allowed.