The program asks user to enter five single characters separated by spaces, and depending on the characters, it will generate a random number.
Here are the rules to follow exactly:
- If input character is 'a', program will generate a random number from 1 to 20.
- If input character is 'e', program will generate a random number from 21 to 40.
- If input character is 'i', program will generate a random number from 41 to 60.
- If input character is 'o', program will generate a random number from 61 to 80.
- If input character is 'u', program will generate a random number from 81 to 100.
- If input character is not one of the above characters, display a 0 in the output.
Here are some sample runs:
Run 1
This program plays a simple random number game.
Enter 5 vowel characters (a,e,i,o,u) separated by spaces: a e i o u
The random numbers are 10 25 46 69 99
---------------------------------------------------------------
Run 2
This program plays a simple random number game.
Enter 5 vowel characters (a,e,i,o,u) separated by spaces: a e a u o
The random numbers are 10 25 4 99 66
---------------------------------------------------------------
Run 3
This program plays a simple random number game.
Enter 5 vowel characters (a,e,i,o,u) separated by spaces: a z i e o
The random numbers are 10 0 43 29 76
---------------------------------------------------------------
Run 4
This program plays a simple random number game.
Enter 5 vowel characters (a,e,i,o,u) separated by spaces: a z i f o
The random numbers are 15 0 47 0 74
What I have tried:
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;
int main()
{
srand(time(0));
const int GAP = 6;
int num;
int none = 0;
char alphabet;
char letter1, letter2, letter3, letter4, letter5;
letter1 = 'a';
letter2 = 'e';
letter3 = 'i';
letter4 = 'o';
letter5 = 'u';
cout << "This program plays a simple, random number game." << endl;
cout << "Enter five vowel characters (a,e,i,o,u) in any order separated ";
cout << "by spaces: ";
cin >> alphabet >> alphabet >> alphabet >> alphabet >> alphabet;
alphabet = num;
cout << "The five random numbers are: " << setw(GAP) << num << setw(GAP);
cout << setw(GAP) << num << setw(GAP) << num;
cout << setw(GAP) << num << setw(GAP) << num;
if (alphabet == letter1)
cout << setw(GAP) << rand() % 19 + 1;
else if (alphabet == letter2)
cout << setw(GAP) << rand() % 19 + 21;
else if (alphabet == letter3)
cout << setw(GAP) << rand() % 19 + 41;
else if (alphabet == letter4)
cout << setw(GAP) << rand() % 19 + 61;
else if (alphabet == letter5)
cout << setw(GAP) << rand() % 19 + 81;
else
cout << none << endl;
return 0;
}