用n-y-n回答前3个问题。最后的陈述应该已经停止,而是改为下一个问题。
如果你愿意,请忽略其余部分。如果有任何错误,请告诉我。
我目前正在第一次参加编程课程,所以对我很温和
#include <iostream>
using namespace std;
int main()
{
//Tattoo Decision
char ans;
cout <<"This program will help you determine whether you should get a tattoo or not?";
cout <<"\nPlease answer the questions with either y (yes) or n (no)";
cout <<"\n\n\nAre you Drunk?: ";
cin >>ans;
switch (ans) //finished
{
case 'y':
{
cout <<"\n\nWell, for obvious reasons, Don't get a tattoo'";
break;
}
case 'n':
{
cout <<"\n\nAre your friends egging on you?: ";
cin>>ans;
switch(ans)//finished
{
case 'y':
{
cout <<"\n\nAre they laughing?: ";
cin >>ans;
switch(ans)//finished
{
case 'y':
{
cout<<"\n\nDon't get a tattoo";
break;
}
case'n':
{
cout<<"\n\nLaughing or not, Don't get a tattoo";
break;
}
}
}
case'n':
{
cout<<"\n\nDoes the tattoo have a special meaning to you?: ";
cin>>ans;
switch(ans)//finished
{
case'y':
{
cout<<"\n\nIs it a name?: ";
cin>>ans;
switch(ans)//unfinished
{
case'y':
{
cout<<"\n\nIs it your significant other?: ";
cin>>ans;
switch(ans)//unfinished
{
case'y':
{
cout<<"\n\nDon't fucking get that tattoo'";
break;
}
}
}
}
}
case'n':
{
cout<<"\n\nThen why are you getting a tattoo for? Don't get one";
break;
}
}
}
}
}
}
return 0;
}
答案 0 :(得分:0)
您似乎错过了break
,请尝试按以下方式添加:
int main()
{
//Tattoo Decision
char ans;
cout <<"This program will help you determine whether you should get a tattoo or not?";
cout <<"\nPlease answer the questions with either y (yes) or n (no)";
cout <<"\n\n\nAre you Drunk?: ";
cin >>ans;
switch (ans) //finished
{
case 'y':
{
cout <<"\n\nWell, for obvious reasons, Don't get a tattoo'";
break;
}
case 'n':
{
cout <<"\n\nAre your friends egging on you?: ";
cin>>ans;
switch(ans)//finished
{
case 'y':
{
cout <<"\n\nAre they laughing?: ";
cin >>ans;
switch(ans)//finished
{
case 'y':
{
cout<<"\n\nDon't get a tattoo";
break;
}
case'n':
{
cout<<"\n\nLaughing or not, Don't get a tattoo";
break;
}
}
break; // <---------- *****
}
case'n':
{
cout<<"\n\nDoes the tattoo have a special meaning to you?: ";
cin>>ans;
switch(ans)//finished
{
case'y':
{
cout<<"\n\nIs it a name?: ";
cin>>ans;
switch(ans)//unfinished
{
case'y':
{
cout<<"\n\nIs it your significant other?: ";
cin>>ans;
switch(ans)//unfinished
{
case'y':
{
cout<<"\n\nDon't get that tattoo'";
break;
}
}
}
}
break; //<--------- *****
}
case'n':
{
cout<<"\n\nThen why are you getting a tattoo for? Don't get one";
break;
}
}
}
}
}
}
return 0;
}