C++では、スイッチのケースで他のデータ型を扱う方法は?
同様のケースはint型とユーザー入力char型です。のC++では、スイッチのケースで他のデータ型を扱う方法は?
int play(Player &Player1, Player &Player2)
{
int answer = 0, guess = 0;
srand(22);
answer = rand() %100;
bool win = false;
while (!win)
{
cout<< "Player1s' turn to guess " <<end1;
guess = Player1.getGuess();
win = checkForWin(guess, answer);
if (win) return 0;
cout<< "Player2's turn to guess " <<end1;
guess = Player2.getGuess();
win = checkForWin(guess, answer);
}
}
int main()
{
system("COLOR 1E");
Humanplayer Player1,Player2;
play(Player1, Player2);
system("pause");
getch();
}
**left window**
:start
{
cout<<"Select Options \n";
cout<<" 1 for Human vs Human\n 2 for Human vs Computer\n 3 for Computer vs Computer
cin>>opt;
switch(opt)
{
case 1:
play(Player1, Player2);
break;
case 2:
play(Player1, Comp1);
break;
case 3:
play(Comp1, Comp2);
break;
default:
cout<<" Invalid entry!!!\n Please enter 1,2 or 3!!!\n";
goto start;
}
}
**right window**
Select Options
1 for Human vs Human
2 for Human vs Computer
3 for Computer vs Computer
h
intは、私がスイッチでこれを処理する方法がわからない場合は、ユーザーの代わりに文字を入力した場合。
コードをテキストとして送信してください。誰もそれをコンパイルするために再入力しません。 –
私は今コードを投稿する方法はありません、私はここに新しい....あなたが助けることができますか? –
[こちら](http://stackoverflow.com/questions/16388510/evaluate-a-string-with-a-switch-in-c/16388610#16388610)を試してください。もちろんC++ 11を使用しています。 –