Arghh char help!

I am offering the player a yes or no decision and have coded it like this
Char Decision;
Char Positive ;
Char Negative
Char Both;
Char Neither;
Positive = 'y'
Negative = 'n'
Both = 'y' or 'n';
Neither != Both;
Cin>> Decision
If (Decision = 'y')
{Do this}
Else if ( Decision = 'n')
{Do this}
Else while ( Decision != 'y' or 'n')
{Cout<<"type either y or n" << endl;}
I did try using Negative instead of n, Positive instead of y, etc. But that wouldn't work at all so I reverted to this, I can get it to work if y is hit, if n is hit, but if for example j is hit, rather than going onto the loop of unless you hit y or n you're not going anywhere, it instead does the (Decision = y) bit.
Am I going about this completely incorrectly?
Is this the correct way to use chars?
This is the first time I've coded properly in about 1 year + so I am very rusty!
Please use code tags in the future
http://www.cplusplus.com/articles/z13hAqkS/

In your if statements you are using = instead of ==
= is for assignments to variables
== is for comparison of equality

if( x = 5 ) will assign the value of 5 to x, the assignment returns the value that was assigned (in this case that would be 5), and any non-zero value is typically evaluated as true.
http://www.cplusplus.com/forum/articles/3483/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

int main()
{
    char decision = ' ';
    cout << "What is your decision? y/n ";
    cin  >> decision;
    while (decision != 'y' && decision != 'n')
    {
            cout << endl << "Enter y or n. Try again.";
            cin  >> decision;
    }

    if (decision == 'y')
        cout << endl << "YOU CHOSE YES" << endl;
    else
        cout << endl << "YOU CHOSE NO" << endl;

    return 0;
}

Topic archived. No new replies allowed.