C++中while循环的难点 我的C++任务有困难。 第一个问题在循环的末尾,答案是!=很遗憾,yes&&customers
将if-else条件置于while循环之外,并删除coutStackoverflow不是一个分配解决服务。我们可以研究您的第一个问题,但要求如何简化代码而不显示您所做的尝试超出了我们的范围。首先,您应该正确格式化代码,并调整程序以直截了当。您确定可以使用!=要比较两个字符串的内容?除了@roelofs所说的,也许CodeReview会是一个更好的地方来征求关于如何简化这一点的建议。其他的就足够了。@cantordust修复了C++中while循环的难点 我的C++任务有困难。 第一个问题在循环的末尾,答案是!=很遗憾,yes&&customers,c++,C++,将if-else条件置于while循环之外,并删除coutStackoverflow不是一个分配解决服务。我们可以研究您的第一个问题,但要求如何简化代码而不显示您所做的尝试超出了我们的范围。首先,您应该正确格式化代码,并调整程序以直截了当。您确定可以使用!=要比较两个字符串的内容?除了@roelofs所说的,也许CodeReview会是一个更好的地方来征求关于如何简化这一点的建议。其他的就足够了。@cantordust修复了 #include <iostream> // Access
#include <iostream> // Access output and input stream
#include <string> // Access string variable
using namespace std;
int main() {
int characters, food, movie, customers=0; //Declare variables
char gender; //Declare variables
string name, answer; //Declare variables
cout <<"Is there a customer? <enter yes if there is and anything else to end program>"<<endl;
cin>>answer;
while (answer == "yes")
{
customers++;
cout <<"\nWhat is your name dear? ";
cin >> name;
cout <<"Well "<<name<<", welcome to my salon!\n";
cout <<"I will ask you a few questions and your answers will determine which haircut I will give you.\nPlease enter your choice by using the character between < > next to your choice.\n\n";
cout <<"Are you <m>ale or <f>emale? ";
cin >>gender;
if (gender == 'm')
{
cout <<"Are you a Super Hero<0> or a Super Villain<1>? ";
cin >>characters;
if (characters == 1)
{cout <<name <<", You should get a mohawk.\n";}
else if (characters == 0)
{
cout <<"OK "<<name<<", do you prefer steak<0> or sushi<1>? ";
cin >>food;
if (food == 0)
cout <<name<<", You should get a flat top.\n";
else if (food == 1)
cout <<name<<", You should get a pompadour.\n";
}
cout <<"Hope you like it!!\n------------\n";
}
else if (gender == 'f')
{
cout <<"Are you a Super Hero<0> or a Super Villain<1>? ";
cin >>characters;
if (characters == 1)
{cout <<name <<", You should get a mohawk.\n";}
else if (characters == 0)
{
cout <<"OK "<<name<<", do you prefer anime<0> or sitcom<1>? ";
cin >>movie;
if (movie == 0)
cout <<name<<", You should go with bangs.\n";
else if (movie == 1)
cout <<name<<", You should go with feathered.\n";
}
cout <<"Hope you like it!!\n------------\n";
}
cout <<"Any other customers? <enter yes if there are and anything else if I am done for the day> "<<endl;
cin >>answer;
if (answer != "yes" && customers >= 5)
cout<<"\nWell that was a good day! I had " <<customers<<" customer<s> today. Tomorrow is another day ..."<< endl;
else if (answer != "yes" && customers < 5)
cout<<"\nWell that was a poor day! I had " <<customers<<" customer<s> today. Tomorrow is another day ..."<< endl;
}
cout<<"\nWell that was a poor day! I had " <<customers<<" customer<s> today. Tomorrow is another day ..."<< endl;
return 0;
}
while (answer == "yes")
{
...
}
if (customers >= 5)
cout<<"\nWell that was a good day! I had "
<<customers
<<" customer<s> today. Tomorrow is another day ..."
<< endl;
else
cout<<"\nWell that was a poor day! I had "
<<customers
<<" customer<s> today. Tomorrow is another day ..."
<< endl;