Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int uInput;
- cout << "Enter 1 to generate a random number 1-10\n";
- cout << "Enter 2 to generate a random number 1-100\n";
- cout << "Enter 3 to generate a random number 1-1000\n";
- cout << "Enter Here: ";
- cin >> uInput;
- switch(uInput)
- {
- case 1:
- {
- srand(static_cast<unsigned int>(time(0))); //Seed random number with current time.
- int rndNum1 = rand() % 10 + 1;
- cout << "Randomly Generated Number: " << rndNum1 << endl;
- break;
- }
- case 2:
- {
- srand(static_cast<unsigned int>(time(0))); //Seed random number with current time.
- int rndNum1 = rand() % 100 + 1;
- cout << "Randomly Generated Number: " << rndNum1 << endl;
- break;
- }
- case 3:
- {
- srand(static_cast<unsigned int>(time(0))); //Seed random number with current time.
- int rndNum1 = rand() % 1000 + 1;
- cout << "Randomly Generated Number: " << rndNum1 << endl;
- break;
- }
- default:
- {
- cout << "Invalid\n";
- }
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement