2017-10-11 4 views
-2

Dieser Code wurde entwickelt, um den endgültigen Preis eines Artikels basierend auf der Kundenmenge zu ermitteln. Ich habe bereits in den Gleichungen hinzugefügt, aber wenn es ausgeführt wird, werden der Rabatt und der Endpreis nicht richtig ausgewertet. Wenn jemand weiß, wo ich im Pseudocode falsch gelaufen bin, wäre das sehr hilfreich.Rabattcode .. Wo bin ich falsch gelaufen?

using namespace std; 
int main() { 

    // Variables 
    double Retail, quantity, discount1, discount2, discount3, discount4, TotalCost1, TotalCost2, TotalCost3, TotalCost4; 
    Retail = 99; 
    quantity = 0; 
    discount1 = (quantity * Retail) * .20; 
    discount2 = (quantity * Retail) * .30; 
    discount3 = (quantity * Retail) * .40; 
    discount4 = (quantity * Retail) * .50; 
    TotalCost1 = quantity - discount1; 
    TotalCost2 = quantity - discount2; 
    TotalCost3 = quantity - discount3; 
    TotalCost4 = quantity - discount4; 

    //Equations 
    cout << "Please enter the quantity of items you would like to purchase: " << endl; 
    cin >> quantity; 
    cout << "The number of items being purchased is: " << quantity << endl; 

    if (quantity <= 19) { 
     cout << "Your final price is: " << discount1 << endl; 
    } 
    if (quantity >= 20) { 
     cout << "Your final price is: " << discount2 << endl; 
    } 
    if (quantity >= 50) { 
     cout << "Your final price is: " << discount3 << endl; 
    } 
    if (quantity >= 100) { 
     cout << "Your final price is: " << discount4 << endl; 
    } 




     system("pause"); 
} 
+2

Bitte seien Sie spezifischer über Sie, was bedeutet "es läuft nicht richtig." Sehen Sie sich auch [mcve] an. Sie haben den Code, Sie müssen nur detaillierter zu dem spezifischen Problem sein, dem Sie gegenüberstehen. – Lexi

+1

Post echten Code und die spezifischen Fehler, die Sie bekommen. –

+4

Was ist 'if (Menge <= 19, Rabatt1)' für? – doctorlove

Antwort

1

Ist es nur, dass Sie Menge ist nicht als etwas außer 0 definiert, bevor Sie die Rabatte berechnen? Ich habe das Lesen Ihres Einkaufs vor den Berechnungen verschoben und bessere Ergebnisse erzielt (mit Online-Compiler).

double Retail, quantity, discount1, discount2, discount3, discount4, TotalCost1, TotalCost2, TotalCost3, TotalCost4; 
Retail = 99; 
quantity = 0; 

//Equations 
cout << "Please enter the quantity of items you would like to purchase: " << endl; 
cin >> quantity; 
cout << "The number of items being purchased is: " << quantity << endl; 

discount1 = (quantity * Retail) * .20; 
discount2 = (quantity * Retail) * .30; 
discount3 = (quantity * Retail) * .40; 
discount4 = (quantity * Retail) * .50; 
TotalCost1 = quantity - discount1; 
TotalCost2 = quantity - discount2; 
TotalCost3 = quantity - discount3; 
TotalCost4 = quantity - discount4; 


if (quantity <= 19) { 
    cout << "Your final price is: " << discount1 << endl; 
} 
if (quantity >= 20) { 
    cout << "Your final price is: " << discount2 << endl; 
} 
if (quantity >= 50) { 
    cout << "Your final price is: " << discount3 << endl; 
} 
if (quantity >= 100) { 
    cout << "Your final price is: " << discount4 << endl; 
} 


Please enter the quantity of items you would like to purchase: 
The number of items being purchased is: 19 
Your final price is: 376.2 
+3

'if (Menge <= 19, Rabatt1)' ist fast sicher ein anderes Problem. –

+1

Ich schlug eine Änderung vor, um die, discount1 zu entfernen. – JosephDoggie

+1

Fertig. Ehrlich gesagt ist C++ nicht meine stärkste Fähigkeit. Ich habe mich in einer if-Anweisung über meinen C++ - Komma-Operator informiert. – Joshua

Verwandte Themen