我在Mac OS Sierra上使用Eclipse 4.6.3。如何随机化C++中的输出
所以我有这样的代码:
int main()
{
int GameState = ROOM1;
int iRoomCounter[4] = {0,0,0}; // Used to determine if a room has been visited.
string choice;
char Name[25];
cout << "!!!Hello World!!!" << endl;
cout << "Enter Your Name!" << endl;
cin >> Name;
cout << "Thank you " << Name << ". You will not be forgotten." << endl;
while(GameState != DEATH)
{
switch(GameState)
{
case ROOM1:
{
if (iRoomCounter[0] == 0)
{
cout << "\n One day, " << Name << " was walking through a field and spotted a little Ejay." << endl;
cout << Name << " also spotted a cat. He wanted to pet both, but he could only pet one." << endl;
iRoomCounter[0] = 1;
}
cout << "\nWhich one will he pet?" << endl;
cout << "Ejay" << endl;
cout << "Cat" << endl;
cout << "-> ";
cin >> choice;
if(choice == "Ejay" || choice == "ejay")
{
cout << "He pet Ejay" << endl;
}
}
}
}
}
我有两个问题。如果你只回答一个问题,那很好。但我想有人回答另一个问题。
我想某些随机的输出,例如: 如果让我选择“EJAY”,我想它要么说“他EJAY宠物”或“跑EJAY离开。”或“Ejay死了”。我不知道该怎么做。有人会在我的代码中实现这种方式吗?先谢谢你。
我一直在努力弄清楚如何将我的代码导出到应用程序中。我研究过,没有找到任何东西。我在Mac上使用Eclipse,这可能是原因之一。有人会告诉我该怎么做吗?
谢谢大家!
***我有两个问题。如果你只回答一个问题,那很好。但是我希望有人回答其他问题。***通常,每个问题的StackOverflow是1个问题,特别是当主题完全不同时。 – drescherjm
***我一直在努力弄清楚如何将我的代码导出到应用程序中。***我不知道这个问题是什么意思。我的意思是你的代码看起来像一个应用你想为你的应用程序创建一个安装程序吗? – drescherjm
你可能会想过它。您可以使用随机数字帮助您在字符串A或字符串B之间进行选择,然后将其用作响应。 – gavsta707