Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法找到解决方案_C++_Visual Studio_Procedural Programming - Fatal编程技术网

C++ 无法找到解决方案

C++ 无法找到解决方案,c++,visual-studio,procedural-programming,C++,Visual Studio,Procedural Programming,编辑:在对我的代码进行修改后,它会正常工作。我对C++是新的,所以我确信它对你们中的一些人来说是不正确的,你可能会发现错误或不符合道德的东西。请一定要让我知道,如果有什么我可以改善在这个计划 #include <iostream> #include <string> #include <cstdlib> using namespace std; int main() { // CUSTOMER TYPE string customertype; st

编辑:在对我的代码进行修改后,它会正常工作。我对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 << "\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; 
}
#包括
#包括
#包括
使用名称空间std;
int main(){
//客户类型
字符串自定义类型;
字符串类类型;
串难型;
//类类型
弦乐芭蕾舞;
串莎莎;
宝莱坞;
//难度类型
浮动初学者=0;
浮动中间值=0;
浮动高级=0;
//客户类型输入
cout>客户类型;
如果(客户类型==“特许权”){
}else if(customertype==“child”){
}else if(customertype==“成人”){
}否则
库特
此
cin
语句中的逗号不完全符合您的要求。在此表达式中,只接受
cin>>初学者的输入,而完全忽略其他两个变量

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

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";
字符串选择;
cout>choice//不需要使用getline(),因为您只需要一个单词作为输入
如果(选项==“初学者”)
//做事
else if(选项==“中间”)
//做事
else if(选项==“高级”)
//做事
其他的

听起来你可以使用。
cin>>让步,儿童,成人;
不做你认为它能做的。@NathanOliver我觉得它接受的输入是让步,儿童或成人?如果我错了,请纠正我。不。这是逗号运算符。在这种情况下,
cin>>让步
是唯一正确的做一些事情。
,儿童,成人;
基本上被忽略。请参阅:@NathanOliver Ahhh。那么我该如何将这三个输入分离开来?虽然在您的情况下,看起来您需要读入变量,然后决定做什么。这有点复杂,将在本书中介绍。这需要三个输入from是该程序不正确的用户。我希望程序根据三种输入定义一个答案。例如,如果用户输入
child
,则每个难度选项的成本将降低1.50。@FutureProgrammer您希望该程序有多少输入?那么为什么在cin语句中使用3个变量?@FutureProgrammer刚刚更新了我的答案,这就是你要找的吗?是的。非常感谢。我尝试了使用if…else if…else,虽然我不能完全正确。我必须尝试一下
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";