Random Looping
Oct 1, 2012 at 3:19pm UTC
I am trying to find a random number in between two variables that the user inputs max and min.I need to do this ten times. I seem to be having trouble. Any pointers on how to fix?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
cout << "Max?" << endl;
cin >> maximum;
cout << "Min?" << endl;
cin >> minimum;
srand(time(0)); //seed the random number
double high=maximum;
double low=minimum;
for (int i=1; i<=10; i++ )
{
random_number = rand () % (high - low + 1) + low;
}
Oct 1, 2012 at 3:49pm UTC
(high - low + 1) = double
you cannot apply mod [%] operator on non integral types.
try changing all you variables to ints.
the rest of your logic appears to be good.
Topic archived. No new replies allowed.