Write a program using four enumerators. Initialize each as follows: 1. first, se
ID: 3765143 • Letter: W
Question
Write a program using four enumerators. Initialize each as follows: 1. first, second, third, fourth, fifth, sixth, seventh, eighth, ninth 2. Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday 3. curve, fast, knuckle, slider 4. single, double, triple, homer The program should prompt a user to input a character array or 4 numbers pertaining to each enumerator. Display help text to assists the user. The help text should display the smallest and largest possible values for each inputted number. Validate the input. Display an error message for a number entered outside the range of the enumerator. Using the enumerators, generate a sentence that will display as follows: In the fifth inning on Saturday, I hit a fast ball for a triple. ; where (fifth, Saturday, fast and triple) are printed using the input generated from their respective enumerators. The input that produced the statement above would be: 4612 The program should loop allowing the user to decide whether or not he or she wishes to process the loop again. This is C++ code(language)
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
int main()
{
enum one{first, second, third, fourth, fifth, sixth, seventh, eighth, ninth};
enum two{Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
enum three{curve,fast,knuckle,slider};
enum four{single,doble,triple,homer};
char c='y';
//Fruits myFruit;
int i,j,k,l;
string value1,value2,value3,value4;
while(c=='y'||c=='Y'){
cout << "Please enter the number betwen(0 and 8)";
cin >> i;
while(!(i>=0&&i<=8)){
cout<<"invalid input"<<endl;
cout << "Please enter the number betwen(0 and 8)";
cin >> i;
}
cout << "Please enter the number betwen(0 and 6)";
cin >> j;
while(!(j>=0&&j<=6)){
cout<<"invalid input"<<endl;
cout << "Please enter the number betwen(0 and 6)";
cin >> j;}
cout << "Please enter the number betwen(0 and 3)";
cin >> k;
while(!(k>=0&&k<=3)){
cout<<"invalid input"<<endl;
cout << "Please enter the number betwen(0 and 3)";
cin >> k;
}
cout << "Please enter the number betwen(0 and 3)";
cin >> l;
while(!(l>=0&&l<=3)){
cout<<"invalid input"<<endl;
cout << "Please enter the number betwen(0 and 3)";
cin >> l;}
switch(i)
{
case first:
value1="first";
break;
case second:
value1="second";
break;
case third:
value1="third";
break;
case fourth:
value1="fourth";
break;
case fifth:
value1="fifth";
break;
case sixth:
value1="sixth";
break;
case seventh:
value1="seventh";
break;
case eighth:
value1="eighth";
break;
case ninth:
value1="ninth";
break;
}
switch(j)
{
case Sunday:
value2="Sunday";
break;
case Monday:
value2="Monday";
break;
case Tuesday:
value2="Tuesday";
break;
case Wednesday:
value2="Wednesday";
break;
case Thursday:
value2="Thursday";
break;
case Friday:
value2="Friday";
break;
case Saturday:
value2="Saturday";
break;
}
switch(k)
{
case curve:
value3="curve";
break;
case fast:
value3="fast";
break;
case knuckle:
value3="knuckle";
break;
case slider :
value3="slider ";
break;
}
switch(l)
{
case single:
value4="single";
break;
case doble:
value4="double";
break;
case triple:
value4="triple";
break;
case homer :
value4="homer ";
break;
}
cout<<"In the "<<value1<<" inning on "<<value2<<" , I hit a "<<value3<<" ball for a "<<value4<<endl;
cout<<"Want to continue(y/n)"<<endl;
cin>>c;
}
getchar();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.