Can't redo the loop! :(

ok so I posted recenly asking how to do the average. My program is technicaly complete, with one problem. If I want to play the game again (y||Y) it only gives me a multiplication problem once instead of the 5. Here is my code so far.

#include<iostream>
#include<cmath>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
char again;
int a, b, answer, guess ,count=1;
short int average;
float collect=0;

cout<< "Welcome, I hope you remember your multiplication tables:"<<endl;
cout<<endl;

{again='y';
true;
while ((again=='y') || (again=='Y'))
{
do{
srand ((unsigned)time(NULL) );
a = rand() % 10;
b = rand() % 10;

cout << "\nWhat's " << a << "x" << b << "?: ";
cin >> guess;

answer=a*b;

{if(answer == guess)
{cout << "Correct!"<<endl;
++collect; }


else
if(answer != guess)
cout << "wrong!" << endl;
}
count++;

} while(count<6);

if(collect) average=(collect/5)*100; // if collect is positive value then it will be done here

else average = 0; //if no correct answers so far than do not divide with 0
cout<<"\nAverage"<< average<<"%"<<endl;

cout<<"\nWould you like to play again (y/n) ?"<<endl;
cin>>again;}

if (again=='n'||again=='N')
{
if (average>75)
cout<<"\nThank You for playing!"<<endl;
else
if (average<75)
{
cout<< "\nYou need to study the multiplication table:"<<endl;
cout<<"\n1 2 3 4 5 6 7 8 9"<<endl
<<"2 4 6 8 10 12 14 16 18"<<endl
<<"3 6 9 12 15 18 21 24 27"<<endl
<<"4 8 12 16 20 24 28 32 36"<<endl
<<"5 10 15 20 25 30 35 40 45"<<endl
<<"6 12 18 24 30 36 42 48 54"<<endl
<<"7 14 21 28 35 42 49 56 63"<<endl
<<"8 16 24 32 40 48 56 64 72"<<endl
<<"9 18 27 36 45 54 63 72 81"<<endl;
}
}
}

system("pause");
return 0;
}
collect is never set back to 0 which will be a problem when calculating the average for successive attempts. The loop fails because count is never reset to 1, so when you start your loop count is at 6 already.
ok...but I don't know how to do it, please help.
How about this:

1
2
3
4
5
6
cout<<"\nWould you like to play again (y/n) ?"<<endl;
cin>>again;
if ( again=='y' || again=='Y' ) {
	collect = 0;
	count = 1;
}
I tried it and It doesn't work... Its the same problem. Only one multiplication and same average.
Ohh I got it, I jut put what you told me at the top before the, |do| THANK YOU SO MUCH!!!!!
It work perfectly fine for me, make sure you move the bracket from cin>>again; to below the if statement. It needs to check the input while still inside the while loop.
Topic archived. No new replies allowed.