当我们必须从选项中选择一个时,这是在 C++ 中做出选择的正确方法吗?
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 0000\n"; count++;
getch();
break;
}
else
否,但这有效
#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 0000\n";
if (a== 'B') cout<<"Welcome to Africa\n";
return 0;
}
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 0000\n"; count++;
getch();
break;
}
else
否,但这有效
#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 0000\n";
if (a== 'B') cout<<"Welcome to Africa\n";
return 0;
}