无法找到解决方案

Unable to find a solution

编辑:修改我的代码后,它可以正常工作。我是 C++ 的新手,所以我确信它对你们中的一些人来说看起来不正确,并且你们可能会发现错误或不是 'ethical' 的东西。如果我可以在此程序中改进任何内容,请告诉我。

#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; 
}
cin >> beginner, intermediate, advanced;

cin 语句中的逗号并不完全符合您的要求。在此表达式中,仅采用 cin >> beginner 的输入,而完全忽略其他 2 个变量。

在单个语句中接受多个输入的一种方法是将它们链接起来:

cin >> beginner >> intermediate >> advanced;

或者,您可以在多行上使用 cin 语句:

cin >> beginner;
cin >> intermediate;
cin >> advanced;

编辑:根据您的评论,您正在寻找类似的东西:

string choice;
cout << "Enter your choice here: ";
cin >> choice // no need to use getline() as you only need one word as input

if (choice == "beginner)
    // do stuff
else if (choice == "intermediate")
    // do stuff
else if (choice == "advanced")
    // do stuff
else
    cout << "Invalid choice";

您需要将此复制到您要求用户从 3 个选项中选择一个的所有其他实例。