I have to come up with a random number generator where it will generate 5 random numbers that are within a range of two number entered by the user. Example: User first enters 1 then 10. Random numbers generated could be 2,3,4,5,8. I can get it to give me 1 random number 5 times, but not 5 different random numbers. Please see below. Any help is appreciated. Thanks!
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main ()
{
int num1, num2, randNum, seed;
cout << "enter number 1.\n";
cin >> num1;
cout << "enter number 2.\n";
cin >> num2;
seed = num1 - num2;
randNum = rand() % seed + 1;
cout << randNum << "\n";
cout << randNum << "\n";
cout << randNum << "\n";
cout << randNum << "\n";
cout << randNum << "\n";
return 0;
}
Aucun commentaire:
Enregistrer un commentaire