I am working on a math tutoring program
that asks the user two random numbers from 10 to 100,
and asks them to key in the correct answer within 5 seconds .the program must ask ten questions showing them and then display the score

Okay. What do you have so far?

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

using std::cout;
using std::cin;
using std::endl;

long int random() {
   srand((unsigned)time(0));
   int random_integer;
   random_integer = (rand()%100)+1;
   return random_integer;
}

int main()
{
for(int index=0; index<10; index++) { 
   x = random();
   y = random();
   total = x+y; 
   cout<<"Enter answer: ";
   cin>>answer;

if (answer == total)
   cout<<"That is correct"<<endl;
else {
cout<<"The true answer is: "<<total<<endl;
    }
}
return 0;
}

You don't actually present the problem to the student - are they supposed to telepathically know what values are returned to x and y?

I would only call srand( ) once, in main( ). The way you are using it, I would expect the same to "random" values to be returned for both x and y.

Lines 11-13 could be combined into just one

return (rand()%100)+1;

which now becomes the entire body of the function.

I don't see where you are keeping count of correct and incorrect attempts.

thats where am stuck

Well you could put two variables, one that will count the correct answers and another one that will count the wrong answers:

#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;

long int random() {
   return (rand()%100+1);
}

int main(){
    srand(time(NULL));
    int x, y, total, answer, correct=0, wrong=0, index=0;
    for (int index=0;index<10;index++) {
           x = random();
           y = random();
           total = x+y;
           cout<<"Q["<<index<<"]\nX: "<<x<<", Y: "<<y<<";\nX+Y = ";
           cin>>answer;
        if (answer == total)
            cout<<"That is correct.\nCorrect answers: "<<++correct<<endl;
        else
            cout<<"The true answer is: "<<total<<"\nWrong answers: "<<++wrong<<endl;
    }
    return 0;
}

hi,pl what language u working on?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.