我目前正在使用 Visual Studio 2010 在 C++ 中制作一个基于控制台的小型文本游戏。我遇到了以下问题;当我输入我的名字并选择难度时,我开始制作介绍性文字并输入:
cout <<"Welcome "<<userName<<"... You are a lone: "<<pickRace<<" Your journey will be a "<<difficulty<<" one.";
我希望它显示为:欢迎布莱克......你是一个孤独的人类/兽人,你的旅程将是一个容易/中等/艰难的旅程。
但我以 Welcome Blake 的身份出现……你是一个孤独的 1/2,你的 jouney 将是一个 1/2/3 的。
我认为这是一个问题,因为我的开关有谁能告诉我我需要如何重写它们以使其显示为名称而不是数字?
原始代码:
cout <<"Please pick your race: \n";
cout <<"1 - Human\n";
cout <<"2 - Orc\n";
int pickRace;
cout <<"Pick your race: ";
cin >>pickRace;
switch (pickRace)
{
case 1:
cout <<"You picked the Human race.\n";
break;
case 2:
cout <<"You Picked the Orc race\n";
break;
default:
cout <<"Error - Invalid imput; only 1 or 2 allowed.\n";
}
int difficulty;
cout <<"\nPick your level diffuculty: \n";
cout <<"1 - Easy\n";
cout <<"1 - Medium\n";
cout <<"3 - Hard\n";
cout <<"Pick your level difficulty: ";
cin >>difficulty;
switch (difficulty)
{
case 1:
cout <<"You picked Easy.\n\n";
break;
case 2:
cout <<"You picked Medium.\n\n";
break;
case 3:
cout <<"You picked Hard.\n\n";
break;
default:
cout <<"Error - Invalid imut; only 1,2 or 3 allowed.\n";
}