+ 1

If statement with word instead of number

um i want try to make a something like text based game. just like there is a question "who is the name of the first avenger" and the answer is "steve rogers" i can't figure out how to make the code works, already using if and switch but i can't figure out how?

11th Oct 2018, 9:12 AM
Kaiser Razer Van Zeng Beelzebub
Kaiser Razer Van Zeng Beelzebub - avatar
8 Answers
+ 3
if(answer == "Steve Rogers") { // do something } No?
11th Oct 2018, 9:45 AM
Anna
Anna - avatar
+ 2
?? Can you explain a bit further what you want to do
11th Oct 2018, 9:17 AM
Rishabh
Rishabh - avatar
+ 2
//Try it on your PC, here, SoloLearn Compiler doesn't support this code :-/ #include <iostream> using namespace std; int main() { string userInput; cout<<"What is the name of the creator of this code?"; cin>>userInput; if(userInput=="Rishabh") { cout<<"Correct"; } else cout<<"Incorrect"; return 0; }
11th Oct 2018, 10:11 AM
Rishabh
Rishabh - avatar
+ 2
Rishabh SL compiler support your code only that it want all input before that code runs Kaiser Razer Van Zeng Beelzebub in C/C++ single quotes are valid for char only while double quotes are valid for string only
11th Oct 2018, 10:16 AM
KrOW
KrOW - avatar
+ 1
um i want try to make a something like text based game. just like there is a question "who is the name of the first avenger" and the answer is "steve rogers" i can't figure out how to make the code works, already using if and switch but i can't figure out how?
11th Oct 2018, 9:25 AM
Kaiser Razer Van Zeng Beelzebub
Kaiser Razer Van Zeng Beelzebub - avatar
+ 1
thanks, i'm using ' instead of " and also the compiler doesn't support it
11th Oct 2018, 10:13 AM
Kaiser Razer Van Zeng Beelzebub
Kaiser Razer Van Zeng Beelzebub - avatar
+ 1
I see. In some (/most) languages, ' is reserved for single characters and " for strings.
11th Oct 2018, 10:16 AM
Anna
Anna - avatar
0
In base to what you will get "halo" from "hello"?
11th Oct 2018, 9:19 AM
KrOW
KrOW - avatar