I have to write a program that randomly displays math problems like 5 + 2 or 3 x 8. I have a seperate function for each of the numbers. So for the first number my function looks like this:
1 2 3 4 5 6 7 8
int randomNumber1(int num1)
{
// Computer picks a number between 1 and 10
srand(time (0));
num1 = rand() % 10;
return num1;
}
But I get an error saying: warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
NOTE: Here are my Directives:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
I call srand() in main function? Then is there any point for me to have this function? I just want this function to return a random number between 0 and 10.
When you call srand(time(0));, you seed the random number generator. If you call it in a function, you will seed it more than once if you call the function more than once, which can cause some problems.
P.S. There really isn't much point in the function, since you can do the same thing easily in main()