I'm trying to make a program that will prompt a user to enter a starting value and an ending value. When that is done, I will take those values and call a function that will create a 100 random numbers for me within those two input values.
Here is the code:
I started the program in a main() function to see if the random numbers do come but they are always out of range. Any help would be great.Code:#include <iostream> #include <cstdlib> #include <time.h> using namespace std; void main() { srand (unsigned int(NULL)); int nRandomNumber = 0; int nStartingValue, nEndingValue; cout << "Enter a starting value: "; cin >> nStartingValue; cout << endl; cout << "Enter an ending value: "; cin >> nEndingValue; cout << endl; for (int j = 0; j < 100; j++) { nRandomNumber = rand() % (nEndingValue + 1) + nStartingValue; cout << nRandomNumber << " "; } }



LinkBack URL
About LinkBacks



