mardi 29 mars 2016

Program recognizes first text output, but not second text output

I'm fairly new to C++ programming, so this is probably a rookie mistake. BUT. (why can't I hide the rest of my code... I want to show ALL of what I'm doing..)

So first off, the start to my code looks like this (headers and such, plus the first few lines of code)

#include <iostream>
#include <string>

using namespace std;

string command; // allows for whole words, surrounded by " "
string playername; // for recalling the player's name
char response; // single characters only, surrounded by ' '

// gonna define any objects as a string as well. If what the user types
matches the conditions, it is a true string.

string object;

int main()
{
do{ // beginning of do/while loop. Do these things while a condition is met.
cout << "What is your name? "; // Prints "What is your name" on the screen
cout << endl;
cin >> playername; // User inputs the value for "playername", which can be
recalled throughout the program
cout << endl;
cout << "Your name is " << playername << "? (Y/N)" << endl; // displays the
text with the newly defined playername
cout << endl;
cin >> response; // User input to define response variable
cout << endl;
cout << endl;
}while ((response != 'y')&&(response != 'Y')); // The condition for this
block of code is the user inputting anything BUT 'y' or 'Y'

And then here's the problem bit:

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")); 

My program will recognise when I put in "look" and "door" (as command and object) and responds with the appropriate "It's a door" line. BUT, when I put in "open" and "door" it just accepts it and ends the program, without displaying the text.

If there is ANY way I can rectify this I would be so very appreciative.

Thank you!

Aucun commentaire:

Enregistrer un commentaire