I have just started learning c++. And to try out what I learned I wrote a short 10 question true or false quiz.
Problem:
1. The only way I can get the answers inputed is by using a 1 for true and a 0 for false.
How can I actually get the user to input either the string (true) or the character (t) etc.
Example of what Im using now:
Code:
cout<<"\nQuestion #1\n";
cout<<"\nThe default IRQ for com 1 is 4\n";
cin>> flag;
if (flag==1) {
cout<<"\nvery good " <<str1 <<" you are correct\n";
}
else if (flag==0) {
cout<<"\nSorry " <<str1 <<" That is incorrect";
cout<<"\nCom 1 and Com 3 both share the IRQ of 4\n";
}
---------------------------------
Here are the variables I am using:
Code:
string str1;
bool flag = 1;
char letter;
2. If you try to type anything other than a 1 or 0 the program just shoots straight to the end. I thought maybe nesting another else if would solve the problem but it doesnt.
3. I added the "Char letter" variable in order to keep the thing from disappearing as soon as you answer the last question.
Code:
cout<<"\nPress 'e' then 'enter' to exit program\n";
cin>>letter;
It works ok, and keeps the program from dissapearing too soon, but I have also read something about "cin.get()"
I tried using that in the beginning but kept getting 'Parse errors"
Cout someone tell me what a parse error is and the correct way to use the cin.get() "command?"
Thank you in advance for your help
Steve