Hello Shadow Kurimeki,
First off: Here is just an example starting on line 14 of your code ...
1 2 3 4 5
|
if ( char1 != "T" || "F")
{
cout<<"You entered an incorrect character please reenter True of False"<<endl;
cin>>char1;
};
| |
If I read your problem correctly, you are getting a message saying that "You entered the incorrect character please reenter True or False" no matter what you enter for each question.
If this is the case, the reason is because the condition (char1 != "T" || "F") in your if statements actually return true every time. The reason for this is that while in english the statement reads, "If char1 is not equal to T or F do the following ... ", in c++ it actually reads like this: "If char1 is not equal to "T" OR IF "F""
This means that in an ||(or) statement, c++ will evaluate both sides of a || and return true if either side is true. Here is the equivalent of your code and maybe it will give you a better understanding:
(char1!="T") || ("F")
Here is what your code should look like to implement what your trying to do:
1 2 3 4 5
|
if ( char1 != "T" && char1 != "F")
{
cout<<"You entered an incorrect character please reenter True of False"<<endl;
cin>>char1;
};
| |
This evaluates to, "if char1 does not equal T and char1 does not equal F ..."
Also, another note that I think you would really like to incorporate into your program to make it possible to add questions in the future without needing to do another hundred lines of code:
Instead of using an if statement for every possible choice, try implementing this little bit of pseudocode:
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
|
int correct = 0;
int incorrect = 0;
string char1, char2, char3, char4, char5, char6;
//Question 1
//Get char1
if(answer is correct)
correct++; //correct = correct + 1;
else //answer incorrect
incorrect++; //incorrect = incorrect + 1;
//Question 2
//Get char2
if(answer is correct)
correct++; //correct = correct + 1;
else //answer incorrect
incorrect++; //incorrect = incorrect + 1;
//Question 3
//etc ...
//Let the user know how he did on the quiz
cout<<"You answered "<<correct<<" correct and "<<incorrect<<"incorrect."<<endl;
| |
Also, one last note. If you are interested in input validation (Making sure the person typed in T or F), read up on how do:whiles work. It makes doing input validation very easy.
Let us know how that works out, any other questions by what I've said just ask.