c++ - If else if, code only resolves to else condition -


i'm trying make pretty basic text adventure test rudimentary skills. basic movement prompts user input, , if matches strings, changes coordinates. know, it's stupid. if, else if, else matching response returns else, if enter 1 of matching strings.

string action; string west = "go west"; string east = "go east"; string north = "go north"; string south = "go south"; string prompt = "don't stand around dagger in ass! something! ";  //i wrote bunch of setup story here, it's irrelevant text output  int vertical = 25; int horizon = 20;  //action begins start: { cout << "what do?" << endl; cin >> action;  if (action == south) {     vertical = vertical - 5;     goto descriptions; } else if (action == east) {     horizon = horizon + 5;     goto descriptions; } else if (action == west) {     horizon = horizon - 5;     goto descriptions; } else if (action == north) {     vertical = vertical + 5;     goto descriptions; } else {     cout << prompt << "(try typing \"go\" followed direction)" << endl;     goto start; }  description: //i put bunch of if, else if, else stuff coordinates describing area down here. 

when type "go east" or "go north", prints prompt string daggers , asses, should print if type else. doing wrong? clarify, i'm using xcode on os x 10.10.3.

cin >> string reads 1 word @ time, not 1 line. if input contains "go north", first >> read "go" , second "north", neither of equal "go north".

use getline read whole line.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -