Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loops with Strings

Status
Not open for further replies.

Enges

Programmer
Nov 13, 2005
5
US
Hi, I am learning C++, and I have been for a little bit more than a week now. So far, the best thing I can do is have the user input a number, and the program will execute a command, or print a message to the screen.

I was wondering how I could use this method with strings? As in, could I have the user type something in, and depending on what they type, a message will appear?

Thanks a million.
 
You could use string type to get your input.
Code:
string YourInput;
cin >> YourInput;
if (YourInput == "jump")
{
    // Do something with jump
}
else if (YourInput == "down")
{
    // Do something with down
}
.
.
.
else cout << "Sorry, I can't do that" << endl;

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Thanks, that worked. But, now I have a new problem.

How can I incorporate pictures in a program, so depending on what the user enters, text will appear, and show the user a picture.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top