Search code examples
c++project

is this is right way to make choice in c++ while we have to choose one from option?


case 1:
    cout<<"what is the name of our country. \n A. india \t\t B. africa \n C.australia \t\t D.america\n";
    if(toupper(getchar()) == 'A' ) // **is this is right way?**
       {

        cout<<"correct. \n you win $100000\n"; count++;
        getch();
        break;
    }
    else

Solution

  • NO but this works

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        char a;
    cout<<"what is the name of our country. \n A. india \t\t B. africa \n C.australia \t\t D.america\n";
    cin>>a;
    if (a== 'A') cout<<"correct. \n you win $100000\n";
    if (a== 'B') cout<<"Welcome to Africa\n";
    
    
        return 0;
    }