第42行的情况不断下降到第49行的情况

问题描述 投票:-2回答:1

用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;
}
c++ switch-statement
1个回答
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;

}

© www.soinside.com 2019 - 2024. All rights reserved.