using string or char with if else statement

i want to programme like this
but i dont know how to use char or string with if else statement:
user will open this program and programme will say "do you want to register"
and user will write yes or no and programme will exit or continue

i wrote an code like this but it doesnt work (this is a programme's basically logic):

#include <iostream>

using namespace std;

int main ()
{
cout << "do you want to register";
char test;
cin >>test;
if(test=='yes')
{
cout << "you said yes";
}
if(test=='no')
{
cout << "you said no";
}

}


or

and i wrote this and it also didnt work:

#include <iostream>

using namespace std;

int main ()
{

string answer;
cout << "do you want to register";
cin>>answer ;
if(answer == yes)
{
cout "you said yes";
}
if(answer == no)
{
cout "you said no";
}




}
A char can hold only one character and is inside single quotes
1
2
char c = 'a'
if (c == 'a')

String can hold many chars and they are in double quotes
string s = "hi there" => if (answer == "yes")

Hope things are clear now.
BTW Any half decent book should tell you this.
Last edited on
yes , now it worked thanks a lot for your help
Last edited on
Topic archived. No new replies allowed.