input question
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?
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?
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.
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?
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.
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"
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"
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
Popular Topics
Advertisement