Hey, problem with a do while loop

Hey all

I need some help with this multiple quiz I'm doing, if got most of it done, however I want it so that if the user types in a letter which isn't one of the answers it will display a statement and then loop back round for them to re-enter another letter

the code if got so far is:


int main()
{
char ans2, ans3, a, b, c, d;
int ans1;
int x;
x=0;

cout<<"Welcome to the Eletrical & Electronic Engineering quiz!\n\n";
cout<<"This quiz is based around Analogue and Digital Electronics, Engineering Mathematics and Electrical Engineering\n\n";
system("PAUSE");
cout<< endl;


do {
cout<<"Question 1\n\n";
cout<<"Electrical Engineering: Who's law is V=IR?\n";
cout<<"a. Ohm\n";
cout<<"b. Kirchoff\n";
cout<<"c. Ohm's\n";
cout<<"d. Dog\n";

ans1 = cin.get();
if (ans1==99)
{
x=x+5;
cout<<"Correct!\n";
}
else if (ans1==98)
{
x=x+1;
cout<<"Nope!\n";
}
else if (ans1==97)
{
x=x+3;
cout<<"Nearly!\n";
}
else if (ans1==100)
{
x=x+0;
cout<<"Way Wrong!\n";
}
} while (ans1<97||ans1>100);

cout<< endl; //*


cout<<"Thank you for taking part in this quiz!\n";
cout<<"Your scoure is "<<x;

cout<< endl; //*

system("PAUSE");
}


upon entering a wrong character the loop does cycle back round to allow you to retry, but it prints the question twice and I don't want that and I also got confused of where i put the statement saying "Please enter either a, b, c or d"

any help would be greatly appreciated :)
if you don't want that the question is repeated then put it before 'do'

where i put the statement saying "Please enter either a, b, c or d"
Just before the while loop ends. You need of course an if statement: if(ans1<97||ans1>100) ...

Topic archived. No new replies allowed.