### Standardized Test

I've only started studying C++ for two weeks but I decided to review what I learned by making a standardized test. Ignore a majority of the variables I set up. My problem is that after making C equal to 5, when I try answering the question with 5 it works but when I answer it with C, it doesn't. Why is this?

 ``12345678910111213141516171819202122232425262728293031`` `````` //Standardized Test Program #include using namespace std ;int main() { //Ways of answering the questions ;int A = 1 ;int B = 3 ;int C = 5 ;int D = 7 ;int E = 69 ;int Score = 0 ;bool T = true ;bool F = false ;char Question1[] = "If a man has three apples at his home\n" "and goes out and buys two more apples,\n" "how many apples does he have in total?\n" "(A - 4), (B - 6), (C - 5), (D - Fish)"; ;{ cout << Question1 << endl; ;char cAnswer1 ;cin >> cAnswer1 ;if (cAnswer1 == '5') { ;cout << "Correct!" << endl;} } }``````
The way you're typing is going to confuse you. Put the semi-colon on the same line and after your statements.

 ``12345678`` `````` int A = 1; int B = 3; int C = 5; int D = 7; int E = 69; int Score = 0; bool T = true; bool F = false;``````

It doesn't work because you didn't code the part. Use the or operator.

 ``12`` ``````if (cAnswer1 == '5' || cAnswer1 == 'C') { ;cout << "Correct!" << endl;}``````
Last edited on
your semicolons are all out of whack, but that isn't the problem.

cAnswer1 is type char and '5', 'C' and 'c' are not the same thing. The if statement will only be true if 5 is entered because they can't be interchanged.
`if(cAnswer1 == 'c')`
would be true if c was entered and
`if(cAnswer1 == 'C')`
would be true if C was entered.

[url]http://www.asciitable.com/[/url]
Thank you, but I'm wondering now if there is any point to setting up the letters with prime numbers.
I didn't understand what the numbers were for in the first place. If they have a purpose some place else, you should point that part out.
It really depends on the programmer/end user.
Topic archived. No new replies allowed.