OK, here's my problem. This is supposed to print out a list of menu items. You choose from the list, then print the bill. My problem is that I can't seem to get the menu items to print out in a tabular format and my printout won't add the items together. I keep getting zeros for the tax and amount due. Any help is greatly appreciated.
Thanks!
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int noOfItems = 8;
struct menuItemType
{
string menuItem;
double menuPrice;
};
void getData(ifstream& inFile, menuItemType mList[], int listSize);
void showMenu(menuItemType mList[], int listSize);
void printCheck(menuItemType mList[], int listSize,
int cList[], int cListLength);
void makeSelection(menuItemType mList[], int listSize,
int cList[], int& cListLength);
bool isItemSelected(int cList[], int cListLength, int itemNo);
int main()
{
menuItemType menuList[noOfItems];
int choiceList[noOfItems];
int choiceListLength;
ifstream inFile;
cout << fixed << showpoint << setprecision(2);
inFile.open("Ch11_Ex3Data.txt");
if (!inFile)
{
cout << "Cannot open the input file. Program Terminates!"
<< endl;
return 1;
}
getData (inFile, menuList, noOfItems);
showMenu(menuList, noOfItems);
makeSelection(menuList, noOfItems, choiceList, choiceListLength);
printCheck(menuList, noOfItems, choiceList, noOfItems);
return 0;
}
void getData(ifstream& inFile, menuItemType mList[], int listSize)
{
char ch;
for (int i = 0; i < listSize; i++)
{
getline(inFile, mList[i].menuItem);
inFile >> mList[i].menuPrice;
inFile.get(ch);
}
}
void showMenu(menuItemType mList[], int listSize)
{
cout << "Welcome to Johnny's Resturant" << endl;
cout << "----Today's Menu----" << endl;
for (int i = 0; i < listSize; i++)
{
cout<<mList[i].menuItem<<setw(15)<<mList[i].menuPrice;
}
}
void printCheck(menuItemType mList[], int listSize,
int cList[], int cListLength)
{
int i;
double salesTax;
double amountDue = 0;
cout << "Welcome to Johnny's Resturant" << endl;
for (i = 0; i < cListLength; i++)
salesTax = amountDue * .05;
cout << left << setw(15) << "Tax " << right << " $"
<< salesTax << endl;
amountDue = amountDue + salesTax;
cout << left << setw(15) << "Amount Due " << right
<< " $" << amountDue << endl;
}
void makeSelection(menuItemType mList[], int listSize,
int cList[], int& cListLength)
{
int selectionNo = 0;
int itemNo;
char response;
cListLength = 0;
cout << "You can make up to " << listSize
<< " single order selections" << endl;
cout << "Do you want to make selection Y/y (Yes), N/n (No): ";
cin >> response;
cout << endl;
while ((response == 'Y' || response == 'y') &&
cListLength < 8)
{
cout << "Enter item number: ";
cin >> itemNo;
cout << endl;
if (!isItemSelected(cList,cListLength,itemNo))
{
cList[cListLength] = itemNo - 1;
cListLength = cListLength + 1;
}
else
cout << "Item already selected" << endl;
cout << "Select another item Y/y (Yes), N/n (No): ";
cin >> response;
cout << endl;
}
}
bool isItemSelected(int cList[], int cListLength, int itemNo)
{
bool found = false;
for (int i = 0; i < cListLength; i++)
if (cList[i] == itemNo - 1)
{
found = true;
break;
}
return found;
}