Write a program using four enumerators. Initialize each as follows: 1. first, se
ID: 3766980 • 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. The enumerator should ask the person input(enter) all the numbers on one line to get the sentence to come out. example the user should enter 4612 on one statement line when program runs to get the sentence.
Explanation / Answer
#include <stdio.h>
#include <string.h>
enum place{first, second, third, fourth, fifth, sixth, seventh, eighth, ninth};
char *place1[]= {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth"};
enum week{ sunday, monday, tuesday, wednesday, thursday, friday, saturday};
char *week1[] ={ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"};
enum shape{curve, fast, knuckle, slider};
char *shape1[]={"curve", "fast", "knuckle", "slider"};
enum runs{single, doublee, triple, homer};
char *runs1[] ={"single", "double", "triple", "homer"};
int main()
{
char in[6];
int flag=0;
char ch;
while(1)
{
flag=0;
printf("enter a four dogits without any space eg:4612 ");
printf("1.Range of first digit = 0-8 ");
printf("range of second digit = 0-6 ");
printf("range of third digit = 0-3 ");
printf("range of fourth digit = 1-4 ");
scanf("%s",&in);
if(strlen(in)!=4)
{
printf("enter only four digits ");
continue;
}
if(in[0]<'0'||in[0]>'8')
{
flag=1;
printf("Error :Range of first digit = 1-9 ");
}
if(in[1]<'0'||in[1]>'6')
{
flag=1;
printf("Error: range of second digit = 1-7 ");
}
if(in[2]<'0'||in[2]>'3')
{
flag=1;
printf("Error: range of third digit = 1-4 ");
}
if(in[3]<'0'||in[3]>'3')
{
flag=1;
printf("Error: range of fourth digit = 1-4 ");
}
if(flag==0)
{
printf("In the %s inning on %s, I hit a %s ball for a %s. ",place1[in[0]-'0'],week1[in[1]-'0'],shape1[in[2]-'0'],runs1[in[3]-'0']);
}
printf("enter 'y' to continue / 'q' to quit ");
scanf("%c",&ch);
if(ch=='q')
break;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.