If's and Chars - Help

Hey guys, i'm having some trouble using chars with if's. I have used const chars but they are really irritating because I need to change the char later on in the program.

here is what I want to do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#import <iostream>
using namespace std;

int main() {
char YN;
cout << Please enter Yes or No;
cin >> YN;
if (YN == "Yes"){
cout << "You said yes";
}
if (YN == "No") {
cout << "You said No";
}
return 0;

}


I want to do something along those lines but without using const chars.

Cheers
Last edited on
First, char can only contain one value YN == "Yes"//will never work , and second, when comparing output from char, use the ' ' symbols.
Uh okay? Do you know how to do it lol?
That your program works it is enough to change the type char to std::string of variable YN. For example. By the way instead of directive #import you shall use directive #include

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>

using namespace std;

int main() 
{
   string YN;

   cout << "Please enter Yes or No: ";
   cin >> YN;

   if ( YN == "Yes" )
   {
      cout << "You said \"Yes\"" << endl;
   }
   else if ( YN == "No" ) 
   {
      cout << "You said \"No\"" << endl;
   }
   else
   {
      cout << "You have to answer either \"Yes\" or \"No\"" << endl;
   }

   return 0;
}
Last edited on
Thanks heaps man :D Legend
Last edited on
Topic archived. No new replies allowed.