+ 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?
8 ответов
+ 3
if(answer == "Steve Rogers") {
// do something
}
No?
+ 2
?? Can you explain a bit further what you want to do
+ 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;
}
+ 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
+ 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?
+ 1
thanks, i'm using ' instead of " and also the compiler doesn't support it
+ 1
I see. In some (/most) languages, ' is reserved for single characters and " for strings.
0
In base to what you will get "halo" from "hello"?