2016-08-04 11 views
-2

Ich bin ein Anfänger C++ - Programmierer und ich habe Probleme mit diesem Mini-Pizza-Programm. Ich habe versucht, eine Reihe von Produkten herzustellen, und wenn der Benutzer eines der Produkte auswählt, sollte das Programm die Menge und den Preis multiplizieren und das Ergebnis ausgeben. Allerdings läuft es aus irgendeinem Grund einfach als Endlosschleife. Alle Hilfe wird sehr geschätzt.für Schleife in Pizza-Programm funktioniert nicht

Hier ist mein Code

include <iostream> 

using namespace std;  

void aboutus(); 
void drinkmenu(); 

int main() 
{ 
    int choice; 
    char quit; 

    cout << "menu" << endl; 
    cout << "press 1 to Exit" << endl; 
    cout << "press 2 to order a drink" << 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); 
    }  
} 

void aboutus() {  
    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; 
} 

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; 

    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..."; 
    system("cls"); 
    cout << "\n\n********************************INVOICE************************\n"; 

    for (int i = 0; i <= c; i++) 
    { 
     result = order[c] * quantity[c]; 
    } 
    cout << "your total is " << result << endl; 
    getchar(); 
} 
+0

'umfassen ' falsch ist. –

+0

Sie wollten wahrscheinlich 'result = order [i] * quantity [i];' in Ihre 'for'-Schleife schreiben. Auch sollte die Bedingung "i

+1

Ich nehme an, dass das ein Kopieren/Einfügen-Problem ist. – drescherjm

Antwort

0

Hier ist das Problem. Ihre while-Schleife muss, bevor der Switch-Anweisung gesetzt werden

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

Try this:

cin >> choice; 
    while (choice != 3) { 

     switch (choice) { 
      case 1: 
       aboutus(); 
       break; 

      case 2: 
       drinkmenu(); 
       break; 

      default: 
       cout << "Invalid option" << endl; 
       break; 
     } 
     cin >> choice; 
    } 

    exit(0); 
Verwandte Themen