无法找到解决方案



编辑:对我的代码进行了修订后,它会尽可能地工作。我是C 的新手,所以我敢肯定,它看起来对你们中的某些人看上去不会正确,并且您可能会发现错误或不是"道德"的事物。请让我知道该程序中是否可以改进任何东西。

#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 << "ntInvalid 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 << "ntInvalid 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 << "ntInvalid Choice" << "n" << endl; 
// CALCULATION
float totalprice = 0;
if ((customertype == "concession") && (difficultytype == "beginner" && "intermediate" && "advanced")) { 
cout << "ntTotal Price: 2.50" << "n" << endl; 
} else if ((customertype == "child") && (difficultytype == "beginner")) { 
cout << "ntTotal Price: 2.50" << "n" << endl; 
} else if ((customertype == "child") && (difficultytype == "intermediate")) {   cout << "ntTotal Price: 3.50" << "n" << endl;
} else if ((customertype == "child") && (difficultytype == "advanced")) {
cout << "ntTotal Price: 4.00" << "n" << endl; 
} else if ((customertype == "adult") && (difficultytype == "beginner")) { 
cout << "ntTotal Price: 4.00" << "n" << endl; 
} else if ((customertype == "adult") && (difficultytype == "intermediate")) {   cout << "ntTotal Price: 5.00" << "n" << endl;
} else if ((customertype == "adult") && (difficultytype == "advanced")) {
cout << "ntTotal Price: 5.50" << "n" << endl; 
} else 
cout << "tInvalid Choice" "n" << "n" << endl; 
cout << "ntCustomer Type: " << customertype << "n" << endl;
cout << "ntClass Type: " << classtype << "n" << endl;
cout << "ntDifficulty 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个选项之一的所有其他实例中复制此内容。

相关内容

  • 没有找到相关文章

最新更新