srand

I'm trying to get my random-equation generator to generate two different numbers not only every time it starts up, but also each time it runs through the while loop. Input is much appreciated.



#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
srand(time(0));
int number1 = rand()%50;
int number2 = rand()%50;
int counter = 0;
int total;
int useranswer;

while (counter<3)
{
total=number1+number2;
cout<<number1<<"+"<<number2<<"\n";
cout<<"Your answer: \n";
cin>>useranswer;
if (useranswer == total)
{
cout<<"Correct!\n";
counter++;
}
else
{
cout<<"Incorrect!\n";
cout<<"The correct answer is: "<<total<< endl;
counter++;
}
}
cout<<"\n The end!\n";
cin.get();
}
Uh, how about calling rand() again in the while loop...?
Thank you! That was rather obvious, I should've seen that. Thanks again!
Topic archived. No new replies allowed.