Hey I posted this once already but twas gone the next day
My problem is that when ever I enter the correct answer for my Cin statement it will still go to the next cout statement and wont cut the the next question
#include<iostream>
#include<string>
usingnamespace std;
int main()
{
string char1, char2, char3, char4, char5, char6;
cout<<"Hello this is your standard True and False quiz"<<endl;
cout<<"Please enter 'T' or 'F'"<<endl;
cout<<"No#1 George Washington invented the toilet?"<<endl;
cin>>char1;
if ( char1 != "T" || "F")
{
cout<<"You entered an incorrect character please reenter True of False"<<endl;
cin>>char1;
};
if ( char1 != "T" || "F")
{
cout<<"You entered an incorrect character please reenter True of False"<<endl;
cin>>char1;
};
if ( char1 == "T" )
{
cout<<"You entered the incorrect answer. The answer is False"<<endl;
};
cout<<"No#2 The Squareroot of 3136 is 56?"<<endl;
cin>>char2;
if ( char2 != "T" || "F")
{
cout<<"You entered an incorrect character please reenter True of False"<<endl;
cin>>char2;
};
if ( char2 != "T" || "F")
{
cout<<"You entered an incorrect character please reenter True of False"<<endl;
cin>>char2;
};
if ( char2 == "F" )
{
cout<<"You entered the incorrect answer. The answer is True"<<endl;
};
cout<<"No#3
system("PAUSE");
return 0;
}
I want it to go and skip the you entered the incorrect character
The first few if statements, where you use the logical or (||) need to have the variable specified for each statement. The compiler is reading:
if ( char1 != "T" || "F")
And getting if(char1 != "T") and if("T"). Since if("T") is always true, it always sayings the character is incorrect. You want:
if(char1 != "T" && char != "F")
You want a logical and because no matter what character you put in, it cannot be both T and F.
EDIT: Also you check every combination of true and false answers. This seems very redundant; why not just increment a variable for each correct answer?
Ahhh my eyes =\ This code needs to be tidied up a lot.
Some comments:
1) use functions. You have A LOT of duplicated code.
2) store your functions in an array, or vector so you can iterate through them.
3) use a parseResponse() or similar function.
4) Dynamically build your response string.
5) If I entered an incorrect response, I am asked to re-enter only once. There is no loop to ensure I enter a valid response.