ok how can i get it so it will ask for a string and the string will be and number of char long.
ex:
hello or hi
and have if check the string to do something like this:
ok you tyeped hello so the program will say "hello to you too"
ok how can i get it so it will ask for a string and the string will be and number of char long.
ex:
hello or hi
and have if check the string to do something like this:
ok you tyeped hello so the program will say "hello to you too"
If you're familiar with the C++ string class, just use cin >> yourString like you would with an int.
Code:string user_input; cout << "Enter a statement: "; cin >> user_input; if ("hello" == user_input) //overloaded <string> class == boolean operator simulates the <cstring> strcmp( ) function { do stuff here } else if ("hi" == user_input) { do stuff here } else { do stuff here }
[edit] moved constants to the left-hand side of the == based on this tip [/edit]
Last edited by The Brain; 07-09-2005 at 01:02 AM. Reason: put constants on the left hand side to avoid possible assignment errors
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
thanx that was easyer than i thought