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;
}

OK, I finally got it to print out in the tabular format, but I still can't get it to add the amounts. I've tried a few different things, but I think my for loop may be wrong. Can someone help, please?

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<<left<<setw(15)<<mList[i].menuItem<<right<<mList[i].menuPrice<<endl;
	cout<<endl;
}

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 < listSize; i++)
	{
		i = amountDue + i;//I think this is wrong....I also tried
                               //amountDue = amountDue + i, but it doesn't work.
                              //I'm not sure if it's the for loop or the formula.

	}
		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;
}

Well, I got the 'for' statement correct, but it still isn't printing a list of choices or adding the amounts. Should I put an 'if' statement in there? Please advise. This is due tonight.

Thanks!

Here's the most recent code that I've done.

#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("Ch12_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 Restaurant" << endl;
	cout << "----Today's Menu----" << endl;

	for (int i = 0; i < listSize; i++)
		cout<<left<<setw(15)<<mList[i].menuItem<<right<<mList[i].menuPrice<<endl;
	cout<<endl;
}

void printCheck(menuItemType mList[], int listSize, 
				int cList[], int cListLength)
{
	int i;
	double salesTax;
	double amountDue = 0;
	
	cout << "Welcome to Johnny's Restaurant" << endl;

	for (i = 0; i < cListLength; i++) //this is where I'm having trouble.
                                                      //the statement is correct, but it
                                                     //isn't picking up the choices.
	{
		cout<<cList[i];
	}
//everything from here on is correct.  I'm just have trouble with the section
//above.
		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;
}

Never mind. I finally figured it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.