Here is the assignment (Part A).
In this part you will write a function to generate random numbers in a specified range. Specicially we want you to write a function named generateRandom that generates a single random number in a range specified by the user. The function takes two integer parameters representing the lower and upper bounds of the range and it returns an integer random number between the lower and upper bound inclusive. For example, if the parameters are 5 and 25, the function will return a random number between 5 and 25. Write a main function that tests this function by:
1) Asking the user for an integer with which to seed the random number generator. Call srand with this integer.
2) Ask the user for a lower and upper bound for the random number.
3) Asking the user how many random numbers to generate
4) Call generateRandom the requested number of times and prints the generated
random numbers.
Here is my code. However, my code prints out the same number instead of a random number each time.
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
int generateRandom(int &Lower_Bound,int &Upper_Bound);//function prototype generate random
void setPrecision(int a, int b); // SetPrecision Prototype
double computePercent(int input1, int input2); // ComputePrecision Prototype
int main()
{
int seed;
int Lower_Bound;
int Upper_Bound;
//int Lower_Bound_Rand;
//int Upper_Bound_Rand;
int RandPrint;
int Range;
//int N;
//Begin Part A:
cout << "Please enter an integer seed for the random number generator: " << endl;
cin >> seed;
cout << "Please enter the lower and upper bounds for the random number: " << endl;
generateRandom(Lower_Bound,Upper_Bound);
cout << "Please enter the number of random numbers you wish to print: " << endl;
cin >> RandPrint;
srand(seed);
Range = rand() % (Upper_Bound - Lower_Bound + 1) + Lower_Bound;
for (int i =0; i<RandPrint; i++){
cout << "Random integer = " << RandPrint << Range << endl;
}
return 0;
}
int generateRandom(int &Lower_Bound,int &Upper_Bound){
cin >> Lower_Bound;
cin >> Upper_Bound;
return (Lower_Bound>>Upper_Bound);
}
void setPrecision(int a,int b){
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
}// SetPrecision function
double computePercent(int input1, int input2){
return 0;
}