input question

Started by
7 comments, last by Zahlman 19 years, 2 months ago
hey, I'm writting a crude little text game to practice what I know. I was wondering if there was a way to leave cin >> blank so the user can type anything they want and then create an if statement on what they input?
Advertisement
what do you mean by 'leave cin >> blank'?
"Game Programming" in an of itself does not exist. We learn to program and then use that knowledge to make games.
so that they can input anything that they want..

and then the program will say if it's a valid statement...

most text game describe the surrounding and then the user inputs...

right?
#include <iostream>#include <string>using namespace std;int main() {  string command; //changed to command  cout<<"What do you want to do?\n";  cin>>command;  if(command == "eat") {    cout<<"You eat.\n";  }  else    cout<<"You do nothing, because I didn't understand it.\n";return 0;}

I think that's what you want.
You just make the if statements the options the person could do.
Meta AdamOne of a million noob C++ programmers.
okay thanks...

I was getting a little bit confused making a string for every option, lol.

but i should have one called...command, for example?
what do you mean? Like a string called "command", well just replace "myString" with command. String is a declared and defined like a type like int or char.
Meta AdamOne of a million noob C++ programmers.
I know that, lol...

I was stating that when I first attempted to do the program I was trying to make a string for every command when in fact all I need was one called command...or as you said "mystring"
Ohh hehe yeah, you only need 1
Meta AdamOne of a million noob C++ programmers.
Be sure you have a clear understanding of the concept of a variable, and specifically its name, type and value, which are all separate concepts.

This topic is closed to new replies.

Advertisement