| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Boolean
Cany anyone give me an example of a boolean? And, is there anyway to combine bools and strings?
|
|
#2
|
|||
|
|||
|
|
|
#3
|
|||
|
|||
|
What I mean is there a way to use a bool or an if statement to do the same thing with words and phrases as they normally do with numbers?
|
|
#4
|
|||||
|
|||||
|
...I'm still unclear. Why don't you provide a sample code of what you're thinking of doing.
You can compare strings with strcmp()... C Code:
...but I don't know if that's what you're getting at. |
|
#5
|
|||
|
|||
|
This is a sample of the code that i am making. Its almost like i want to create a conversation between the user and the computer.
#include <iostream> #include <string> using namespace std; int main() { string Response; string Replyhowareyou; string Replylately; cout<<"Hello\n"; cin>> Response; cin.ignore(); cout<<"How are you?\n"; cin>> Replyhowareyou; cin.ignore(); cout<<"Good, thanks.\n"; cin>> Replylately; cin.ignore(); string hello; cout<< "So what have you been up to lately?\n" ; cin>> hello; cin.ignore(); return 0; } I but i want to add If statements in. But instead of using integers, i want to use words. |
|
#6
|
|||||
|
|||||
|
OK, go ahead. Since you're using the C++ string class, you can compare with the == operator, e.g.
C++ Code:
|
|
#7
|
|||
|
|||
|
Thank you so much, this is awesome!
Now, is there any way for the cin to prompt a response from the cout, instead of the cout always being the one to prompt an imput? |
|
#8
|
|||
|
|||
|
I'm confused again. cout is for output, cin is for input. Period.
|
|
#9
|
|||
|
|||
|
Right, but usually in code cout comes first. Is there any way that you can have the user input data (cin) and then prompt a response from the computer. So have cin come before cout in code.
|
|
#10
|
|||
|
|||
|
Sure, just declare a string variable and put the getline(cin, string_variable) before any cout<< statements. You control cout and cin; there is no defined order.
|
|
#11
|
|||
|
|||
|
Thanks so much! I really appreciate it!
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Boolean |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|