Write a program using four enumerators. Initialize each as follows: 1. first, se
ID: 3538553 • 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 allow the user to decide whether or not he or she wishes to process
the loop again.
*PLZ FOLLOW THE DIRECTIONS GIVEN, WILL RATE 5 STARS TO BEST PROGRAM^
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
string a1[9]={"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth"};
string a2[7]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
string a3[4]={"curve", "fast", "knuckle", "slider"};
string a4[4]={"single", "double", "triple", "homer"};
int valid;
int a[4];
valid=1;
do
{
for(int i=0;i<4;i++)
{
if(i==0)
{
for(int j=0;j<9;j++)
{
cout<<"to select "<<a1[j]<<" press "<<j<<endl;
}
cin>>a[i];
if(a[i]>=9||a[i]<0)
{
cout<<"number entered outside the range of the enumerator."<<endl;
}
}
else if(i==1)
{
for(int j=0;j<7;j++)
{
cout<<"to select "<<a2[j]<<" press "<<j<<endl;
}
cin>>a[i];
if(a[i]>=7||a[i]<0)
{
cout<<"number entered outside the range of the enumerator."<<endl;
}
}
else if(i==2)
{
for(int j=0;j<4;j++)
{
cout<<"to select "<<a3[j]<<" press "<<j<<endl;
}
cin>>a[i];
if(a[i]>=4||a[i]<0)
{
cout<<"number entered outside the range of the enumerator."<<endl;
}
}
else if(i==3)
{
for(int j=0;j<4;j++)
{
cout<<"to select "<<a4[j]<<" press "<<j<<endl;
}
cin>>a[i];
if(a[i]>=4||a[i]<0)
{
cout<<"number entered outside the range of the enumerator."<<endl;
}
}
}
cout<<"in the "<<a1[a[0]]<<" inning on "<<a2[a[1]]<<" , I hit a "<<a3[a[2]]<<" ball for a "<<a4[a[3]]<<"."<<endl;
cout<<"if you want to continue press 1 else 0";
cin>>valid;
}while(valid==1);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.