EDIT: Nachdem ich meinen Code geändert habe, funktioniert es wie es sollte. Ich bin neu in C++, daher bin ich mir sicher, dass einige von Ihnen nicht richtig aussehen werden und dass Sie möglicherweise Fehler oder Dinge finden, die nicht "ethisch" sind. Bitte lassen Sie mich wissen, ob es etwas gibt, das ich in diesem Programm verbessern kann.Konnte keine Lösung finden
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main() {
// CUSTOMER TYPE
string customertype;
string classtype;
string difficultytype;
// CLASS TYPE
string ballet;
string salsa;
string bollywood;
// DIFFICULTY TYPE
float beginner = 0;
float intermediate = 0;
float advanced = 0;
// CUSTOMER TYPE INPUT
cout << "Enter Customer Type: ";
cin >> customertype;
if (customertype == "concession") {
} else if (customertype == "child") {
} else if (customertype == "adult") {
} else
cout << "\n\tInvalid Choice" << "\n" << endl;
// CLASS TYPE INPUT
cout << "Enter Class Type: ";
cin >> classtype;
if (classtype == "ballet") {
} else if (classtype == "salsa") {
} else if (classtype == "bollywood") {
} else
cout << "\n\tInvalid Choice" << "\n" << endl;
// DIFFICULTY TYPE INPUT
cout << "Enter Difficulty Level: ";
cin >> difficultytype;
if (difficultytype == "beginner") {
} else if (difficultytype == "intermediate") {
} else if (difficultytype == "advanced") {
} else
cout << "\n\tInvalid Choice" << "\n" << endl;
// CALCULATION
float totalprice = 0;
if ((customertype == "concession") && (difficultytype == "beginner" && "intermediate" && "advanced")) {
cout << "\n\tTotal Price: 2.50" << "\n" << endl;
} else if ((customertype == "child") && (difficultytype == "beginner")) {
cout << "\n\tTotal Price: 2.50" << "\n" << endl;
} else if ((customertype == "child") && (difficultytype == "intermediate")) { cout << "\n\tTotal Price: 3.50" << "\n" << endl;
} else if ((customertype == "child") && (difficultytype == "advanced")) {
cout << "\n\tTotal Price: 4.00" << "\n" << endl;
} else if ((customertype == "adult") && (difficultytype == "beginner")) {
cout << "\n\tTotal Price: 4.00" << "\n" << endl;
} else if ((customertype == "adult") && (difficultytype == "intermediate")) { cout << "\n\tTotal Price: 5.00" << "\n" << endl;
} else if ((customertype == "adult") && (difficultytype == "advanced")) {
cout << "\n\tTotal Price: 5.50" << "\n" << endl;
} else
cout << "\tInvalid Choice" "\n" << "\n" << endl;
cout << "\n\tCustomer Type: " << customertype << "\n" << endl;
cout << "\n\tClass Type: " << classtype << "\n" << endl;
cout << "\n\tDifficulty Type: " << difficultytype << "\n" << endl;
system("pause");
return 0;
}
Klingt, als könnten Sie ein [gutes C++ Buch] (http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) verwenden. 'cin >> Zugeständnis, Kind, Erwachsener;' tut nicht, was Sie denken, dass es tut. – NathanOliver
@NathanOliver Ich habe den Eindruck, dass es die Eingabe als Konzession, Kind oder Erwachsener nimmt? Bitte korrigieren Sie mich, falls ich falsch liege. – FutureProgrammer
Nein. Es ist der Komma-Operator. In diesem Fall ist "cin >> concession" das Einzige, was etwas bewirkt. ', Kind, Erwachsener;' wird grundsätzlich ignoriert. Siehe: https://en.wikipedia.org/wiki/Comma_operator – NathanOliver