Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************************************************
- * Author: Jared Hughes
- * Date Created: 10/30/2014
- * Last Modification Date: 10/30/2014
- * Filename: randFun.cpp
- *
- * Overview:
- * This program will display a single random number to a user from a
- * range. The range will be decided by the user. The data will be
- * validated to be only integers as well as confirming the range is legal
- *
- * Input:
- * Input will be two integers given by the user. One low end and one high end.
- * These numbers will be validated as integers and validated to make sure the low
- * end is less than the high end.
- *
- * Output:
- * The final output of this program will be a single interger displayed to the user
- * between the range of min and max.
- *
- *
- *********************************************************************************************/
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- void rand_int(const int &min, const int &max, int &val); //Function to be called later - random number generator
- int main ()
- {
- srand(time(0));
- int maximum; //Max range of random number generator
- int minimum; //Minimum range of random number generator
- int value; //value returned from rand_int()
- cout << "This is a random number generator\n";
- cout << "Please input the first interger as your minimum: ";
- while (!(cin >> minimum))
- {
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Please make sure your minimum input is an integer.\n";
- cout << "Please input the first interger as your minimum: ";
- }
- cout << "Please input the second integer as your maximum: ";
- while(!(cin >> maximum))
- {
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Please make sure your maximum input is an integer.\n";
- cout << "Please input the second integer as your maximum: ";
- }
- while(minimum >= maximum)
- {
- cout << "Please make sure your minimum is less than your maximum\n";
- cout << "Please input the first interger as your minimum: ";
- while (!(cin >> minimum))
- {
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Please make sure your minimum input is an integer.\n";
- cout << "Please input the first interger as your minimum: ";
- }
- cout << "Please input the second integer as your maximum: ";
- while(!(cin >> maximum))
- {
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Please make sure your maximum input is an integer.\n";
- cout << "Please input the second integer as your maximum: ";
- }
- }
- rand_int(minimum, maximum, value);
- cout << "Your randomly generated integer between " << minimum << " and " << maximum << " is " << value << "." << endl;
- return 0;
- }
- /*******************************************************
- * Function to pull in two user input integers as range *
- * min and max, will output a single random number *
- * within that range. Will return that value to main *
- *******************************************************/
- void rand_int(const int &min, const int &max, int &val)
- {
- int range; //Numbers in the calculated range;
- range = max - min + 1;
- val = (rand() % range) + min;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement