Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C Program Please write all clear and in steps and comment each step! Use Switch and while loops to write the program What to do
C Program
Please write all clear and in steps and comment each step!
Use Switch and while loops to write the program
What to do Write a C program, that continuously accepts characters from the command line, one at a time. The accepted letters are 'A', 'B' C', 'D', 'F and 'q. While the letter 'q will result in the program to be terminated, any of the other letters will trigger the following output Letter Output Very Good!" Good!" C "Okay!" D or F "Doomed!" Your program keeps prompting for letters and putting out the corresponding responses according to the above table until the letter 'q' is entered, upon which the program will terminate. Any non-accepted letter will output some error message of your choice, telling the user what input is accepted and keep going All of the program's logic will go into the main function. You should convince yourself that you need to have a while loop that keeps accepting input, until 'q is entered and you exit. I want you to find a way to leave the while-loop that does not just return/exit right from within the while loop. Options are to check for a flag in the while loop header, check for the letter to be 'q or use break once the letter 'q is detected in the loop In any case, I want you to handle the different cases how to deal with each of the input characters by way of a switch statement. What to submit l ask you to submit the following The source code of your program A screen shot that demonstrates the proper working of your program as follows Run your program and enter these letters in this order: 'A', 'B', 'C', 'D', 'F', 'G', 'H' and 'q' Hint In class I discussed that your call to scanf) will prompt and wait for you to enter something on the keyboard. You need to understand, however, that entering a character, followed by the return key will enter actually two characters, the second of which is the unwanted carriage return. You will want to get rid of the second character, as it will confuse your program logic. In order ta achieve that, I suggest to call getchar0) right after the call to scanf0, which has the effect of silently discarding the unwanted character
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started