【发布时间】:2016-03-30 06:40:43
【问题描述】:
我对 C++ 编程相当陌生,所以这可能是一个新手错误。但。 (为什么我不能隐藏我的其余代码......我想展示我正在做的所有事情......)
首先,我的代码开始看起来像这样(标题等,加上前几行代码)
#include <iostream>
#include <string>
using namespace std;
string command;
string playername;
char response;
string object;
int main()
{
do
{
cout << "What is your name? ";
cout << endl;
cin >> playername;
cout << endl;
cout << "Your name is " << playername << "? (Y/N)" << endl;
cout << endl;
cin >> response;
cout << endl;
cout << endl;
} while ((response != 'y')&&(response != 'Y'));
}
然后是问题所在:
do
{
cout << endl;
cout << "What will you do?";
cout << endl;
cin >> command >> object;
if ((command == "look")&&(object == "door"))
cout << "You look at the door. It appears to be but a simple wooden door
with a brass handle for opening and shutting. ";
else if ((command == "Open")&&(object == "door"))
cout << "You open the door and proceed to the next room";
} while ((command == "look")&&(command == "Look"));
}
当我输入“look”和“door”(作为命令和对象)时,我的程序会识别并以适当的“It's a door”行响应。但是,当我输入“打开”和“门”时,它只是接受它并结束程序,而不显示文本。
如果有任何方法可以纠正这个问题,我将非常感激。
谢谢!
编辑:为了可读性 EDIT2:将最后一行更改为
}while ((command == "look")||(command == "Look"));
【问题讨论】:
-
虽然编译器不关心格式和缩进之类的事情,但我们人类却关心。请尝试使用缩进来格式化代码,以便于阅读。
-
啊抱歉:S 我很不习惯这个,只是想把所有东西放在一起..