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?
//Standardized Test Program
#include <iostream>
usingnamespace 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;}
}
}
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.