Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Read the following code. For each of the provided example values of category tha

ID: 3871481 • Letter: R

Question

Read the following code. For each of the provided example values of category that might be entered by a user, indicate the final values for rate and total 6 int rate 20; double total 100.0: char category printf Enter the letter of your category: ": scanf(" %c", &category; switch(category) case "M, : rate = rate + 1; case-F' : total = rate * 2; case ‘H' : break; case 'D': rate (int)(total)/8); break; default : total -total rate; break; Sample valuc for category Final valuc of rate is: Final valuc of total is: H' 6. Write a comparable if-else statement for the switch statement above (just start at the beginning of switch)

Explanation / Answer

Program:

#include <stdio.h>

int main(void) {
int rate=20;
double total=100.0;
char category;
printf("Enter the letter of your category: ");
scanf("%c", &category);
switch(category)
{
case 'M' : rate=rate+1;
printf("Final value of rate is: %d ",rate);
printf("Final value of total is: %lf ",total);
case 'F' : total=rate*2;
break;
case 'H' :
case 'D': rate = (int)(total)/8;
printf("Final value of rate is: %d ",rate);
printf("Final value of total is: %lf ",total);
break;
default : total=total+rate;
printf("Final value of rate is: %d ",rate);
printf("Final value of total is: %lf ",total);
break;
}
return 0;
}

Output:

Enter the letter of your category: M

Final value of rate is: 12
Final value of total is: 100.000000

6)Program: Using If else statement

#include <stdio.h>

int main(void) {
int rate=20;
double total=100.0;
char category;
printf("Enter the letter of your category: ");
scanf("%c", &category);
if(category=='M')
{
rate=rate+1;
printf("Final value of rate is: %d ",rate);
printf("Final value of total is: %lf ",total);
}
else if(category=='F')

{
total=rate*2;
}
else if(category=='H'| category=='D')
{
rate = (int)(total)/8;
printf("Final value of rate is: %d ",rate);
printf("Final value of total is: %lf ",total);
}
else
{
total=total+rate;
printf("Final value of rate is: %d ",rate);
printf("Final value of total is: %lf ",total);
}
return 0;

}

Output:

Enter the letter of your category: H

Final value of rate is: 12
Final value of total is: 100.000000

Sample value for category Final value of rate is Final value of total is 'M' 21 100.000000 'H' 12 100.000000 'G' 20 120.000000