I'm trying to write a c++ program that first asks how may people are in a party, then it takes that number to calculate how many times to ask what the next person wants to order. This is what I have so far. I can get the program to recognize how many people I have entered in for the amount of people in a party. What I'm having a problem with is totaling the amount and then displaying the total amount due. The available menu items are a, b, c, d, and x. Each one has a value amount except for x. So if x is entered, then there is no amount to add to the total.

With what I have right now, the program will ask and hold the amount of people in the party. So the program will ask for an order the correct amount of time, but it isn't totaling my cost. So somewhere I'm missing a holder for the total and I'm just not sure on that part. Any help is greatly appreciated.

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main( )
{
	char itemOrdered = ' ';
	double customers = 0.0;
	double total = 0.0;
	int numCustomers = 0;
	
	cout << "Enter number of customers in party: ";
	cin >> numCustomers;
	
	cout << "This program calculates total for " << numCustomers << " customers." << endl;
	
	for (int counter = 0; counter < numCustomers; counter = counter + 1)
	{
    cout << "Our lunch menu today: "  << endl;
	cout << " Combo A: Fried chicken with slaw $4.25" << endl;
	cout << " Combo B: Roast beef and mashed potato $5.75" << endl;
	cout << " Combo C: Fish and chips $5.25" << endl;
	cout << " Combo D: Soup and salad $3.75" << endl;
	cout << "Enter combo code[A/B/C/D] or X for no order: ";
	cin >> itemOrdered;
	itemOrdered = toupper(itemOrdered);

	for (char itemOrdered = 0; itemOrdered < numCustomers;)
	{
		switch(itemOrdered)
		{
			case 'A': total = total + 4.25;
				break;
			case 'B': total = total + 5.75;
				break;
			case 'C': total = total + 5.25;
				break;
			case 'D': total = total + 3.25;
			     break;
            case 'x': total = total + 0.00;
		}
		cout << "Enter next item ordered [A/B/C/D/X] : ";
		cin >> itemOrdered;
		itemOrdered = toupper(itemOrdered);
	}
}
	cout << "Please pay this amount: " << total << endl;

	system("pause");
	return 0;
}

You can use while

while (itemOrdered != 'x')
{
switch(itemOrdered)
{
.
.
.
}
}

Scratch... sorry. I think he's right with the while, except use your count variable. You were getting stuck since your for loop wasn't incrementing itemsOrdered but even doing that your count would be off. Go for the while or do{} while().

(when writing this I had missed that itemsOrdered was a char, but you got it to work so good luck and hope we at least nudged you a bit in the right direction :) )

It looks like I was resetting my count to zero with the second itemOrdered statement. So after I removed that, and some other code, I was able to get it to work correctly. Thanks for the help.

For this program I wasn't able to use a while statement. Here is the code that I was able to get to work. Thanks again for the suggestions.

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main( )
{
	char itemOrdered = ' ';
	double customers = 0.0;
	double total = 0.0;
	int numCustomers = 0;
	
	cout << "Enter number of customers in party: ";
	cin >> numCustomers;
	
	cout << "This program calculates the total due for " << numCustomers << " customers." << endl;
	
	for (int counter = 0; counter < numCustomers; counter = counter + 1)
	{
       cout << "Our lunch menu today: "  << endl;
	cout << " Combo A: Fried chicken with slaw $4.25" << endl;
	cout << " Combo B: Roast beef and mashed potato $5.75" << endl;
	cout << " Combo C: Fish and chips $5.25" << endl;
	cout << " Combo D: Soup and salad $3.75" << endl;
	cout << "Enter combo code[A/B/C/D] or X for no order: ";
	cin >> itemOrdered;
	itemOrdered = toupper(itemOrdered);
	{
		switch(itemOrdered)
		{
			case 'A': total = total + 4.25;
				break;
			case 'B': total = total + 5.75;
				break;
			case 'C': total = total + 5.25;
				break;
			case 'D': total = total + 3.25;
			     break;
                        case 'x': total = total + 0.00;
		}
		itemOrdered = toupper(itemOrdered);
		
	}
}
	cout << "Please pay this amount: " << total << endl;

	system("pause");
	return 0;
}
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.