Problem statement Create a program that outputs a human readable version of a le
ID: 3562926 • Letter: P
Question
Problem statement Create a program that outputs a human readable version of a letter grade, given the latter .. ahem the letter :) The mapping is supposed to be like this: A - > Very good! B - > Good! C - > Okay! ? D or F - > Doomed! Steps you need to follow 1. Identify and document the input(s) and the output(s) 2. Describe the algorithm that solves the problem 3. Write the C program that solves the problem Hints One approach is to use nested if statements - this is what I want you to do. Nested if statements are statements that contain more if statements (which themselves may be nested) in the else branch. If you don't like the idea, you can also get away with just if statements, and no else branches at all, as all of the cases are mutually exclusive. If you want to feel really smart, I invite you to think about the difference of these two approaches :) What to submit Submit two files through BBLearn: One word document that contains your take on steps #s 1&2 A .c file that contains your C program developed in step #3Explanation / Answer
First things first! Apologies. I couldn't give the files you asked for due to some technical difficulties...Hope you understand...
If I understood you correctly this is one of the approach to your problem...use simple if else statements to print the required case.
#include <stdio.h>
int main(void) {
char ch;
scanf("%c",&ch);
if(ch=='A')printf("Very good! ");
else if(ch=='B')printf("Good! ");
else if(ch=='C')printf("Okay!");
else if(ch=='D'||ch=='F')printf("Doomed!");
return 0;
}
Explanation: The above code takes input a character 'ch' which is checked in if statements for different case and output is printed accordingly.
There is also a faster approach in terms of execution time which uses switch case for the same. It is shown below
#include <stdio.h>
int main(void) {
char ch;
scanf("%c",&ch);
switch(ch){
case 'A': printf("Very good! ");
break;
case 'B': printf("Good! ");
break;
case 'C': printf("Okay! ");
break;
case 'D': printf("Doomed! ");
break;
case 'F': printf("Doomed! ");
}
return 0;
}
Explanation: Switch statement takes in a variable and checks for a match of characters...note that all the statements are not executed. Program control will jump directly to the execution statement...and if any statement is executed no further statements are executed.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.