need help with pizza c++ programm

Hi everybody ! i am a begginer c++ programmer and im trying to make a basic pizza programm that takes the users order and then outputs the result.
however at the end it doesnt output the correct total. please help what am i doing wrong?? any help will be very much appereciated. Thanks.

include <iostream>

using namespace std;



void aboutus();
void drinkmenu();



int main()
{

int choice;
char quit;





cout << "menu" << endl;




cout << "press 1 to learn about us " << endl;
cout << "press 2 to order a drink" << endl;
cout << "press 3 to Exit " << endl;

cin >> choice;

switch (choice) {

case 1:

aboutus();
break;

case 2:
drinkmenu();
break;

case 3:exit(0);
break;

default:
cout << "Invalid option" << endl;

while (choice != 3);

return 0;


}



}







void aboutus() {
int choice;
do {
cout << " we are pizza company in buisness from 1999" << endl;
cout << " we support our customers" << endl;

cout << endl;

cout << "we guarantee you a high quality service" << endl;
cout << endl;

cout << " would you like to learn more aabout our company Y/N?" << endl;
cin >> choice;

if (choice == 'Y' && choice == 'y')

{
cout << " Our company was started by Alexander Rodriguez in 1999" << endl;
cout << " since then we have been selling pizza to customers all over the world" << endl;
}

else
{
system("cls");
}

} while (choice != 'Y' && choice == 'y');
}



void drinkmenu() {




double order[10] = { 0.99 , 2.00, 3,00, 0.99, 0.99 , 1.50 , 5.50 , 7.50 ,2.15 };
int result = 0;

char ch = 'Y';
int c = 0;
int quantity[10];
float total = 0;



cout << " Menu" << endl;

cout << "______________" << endl;
cout << endl;

cout << " 1.eporoni pizza.............. price - 0.99$" << endl;
cout << "2 cheese pizza ............... price - 2.00$" << endl;
cout << "3.sicilian pizza.............. price - 3.00$" << endl;
cout << " 4.coke........................ price -0.99$" << endl;
cout << "5.water .........................price - 0.99$ " << endl;
cout << " 6.sprite........................price -1.50$ " << endl;
cout << "7.salad .........................price 5.50$" << endl;
cout << "8.Spaggeti........................price 7.50$" << endl;
cout << "9.regular pizza......................price 2.15$" << endl;
cout << endl;

cout << "\n=================================================>";
cout << "\n PLACE YOUR ORDER";
cout << "\n================================================>\n";

do {



cout << "choose product # " << endl;
cin >> order[c];

cout << "select quantity" << endl;
cin >> quantity[c];

c++;

cout << "do you want another product Y/N?" << endl;
cin >> ch;
} while (ch == 'y' || ch == 'Y');

cout << "\n\nThank You...";

cout << "\n\n********************************INVOICE************************\n";


for (int i = 0; i <=10; i++)
{
result += order[i];


}
cout << "your total is " << result << endl;
system("PAUSE");
getchar();
}
Line 103: You declare order to have 10 elements, but you only initialize 9 prices. order[9] is going to contain garbage. If this array is going to contain prices, perhaps you should call it "prices" and make it const.

Line 138: Why are you doing a cin to your array of prices?

Line 154: You're assuming the person ordered 11 items. You're ignoring how many items were actually ordered.

Lines 154-159: You're adding up the prices (well actually the product numbers), not what the price of what the person ordered.

Line 154: You're going to make an out of bounds reference to order[10]. The elements of order are [0] to [9].

Line 156: You're adding doubles to an int. You're going to lose the decimal portion.

edit:
Line 50: This line will cause an infinite loop if you were to reach it.

Line 81: This condition can never be true.

Line 93: Your condition makes no sense.

Line 103: You have a comma in 3,00


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
thank you very much for the advice ! so how would i make it output the total value at the end ? should i use an if else statement or there is an easier way ?
1
2
3
4
    for (int i=0; i<c; i++)
    {   total += prices[order[i]] * quantity[i];  // Note the revised calculation 
    }
    cout << "your total is " << total << endl;

Topic archived. No new replies allowed.