我对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"));
}
我的程序会当我把在“看”和“门”承认(如命令和对象)并以适当的“这是一扇门”的方式回应。但是,当我放入“打开”和“门”时,它只是接受它并结束程序,而不显示文本。
如果有任何方法可以纠正这一点,我会非常感激。
谢谢!
编辑:为便于阅读, EDIT2:最后一行改为
}while ((command == "look")||(command == "Look"));
,我也得到: the bulwarky that is this code
虽然编译不关心格式化和缩进等事情,我们人类是这样做的。请尝试使用缩进来格式化代码,以便阅读。 –
Aaah对不起:S我很不习惯这个,只是想把所有东西都放在一起.. – KitKatarine