Hello all, I tried a search and I wasn't able to find much. I apologize if a topic like this already exists.
I'm writing a program that requires the user to input two values. It then generates a random number between the two of them. One of the requirements of the assignment however is that the numbers input have to be stored as doubles and not ints. But when I do that it gives me a build error on my rand function. Here is the portion of my code where this occurs. Any help would be appreciated!
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <string>
usingnamespace std;
int main()
{
/*How can I make max_number and min_number doubles and generate a random number between them?*/
int max_number;
cout << "Maximum number: ";
cin >> max_number;
int min_number;
cout << "Minimum number: ";
cin >> min_number;
/*This was how our text book told us to do rand between two values*/
double rand_number = rand() % (max_number - min_number + 1) + min_number;
return 0;
}
I'm doing my best to try and understand how this can help me, but I'm drawing a blank!
Edit: I think you're trying to tell me that I need to add the remainder to my variable, but from that reference it looks like you have to use doubles or floats in the function, which again leads back to my original problem.