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

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

ID: 3870676 • Letter: S

Question


s. 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. int rate20; double total = 100.0; char category printf(entry the letter of your category: "; scanf(“ %c", &category; switch(category) case 'M' rate rate 1; case ‘F' : total rate * 2; break; ‘ H' : "D,: case (int) (total ) /8); rate= break; case default : total= total + rate; break; Sample valuc for category Final valuc of rate is: Final valuc of total is: M' H' 6.) Write a comparable if-else statement for the switch statement above (just start at the beginning of s witch); if (a 75&&avg100;

Explanation / Answer

5.

#include <stdio.h>

int main(void) {

int rate=20;

double total=100;

char category;

printf("Enter the letter of your category");

scanf("%c",&category);

switch(category)

{

case 'M':

rate=rate+1;

case 'F':

total=rate*2;

break;

case 'H':

case 'D':

rate=(int)(total/8);

break;

default:

total=total+rate;

break;

}

printf(" Final value of total %f",total);

printf(" Final value of rate %d",rate);

return 0;

}

Output:

6.

#include <stdio.h>

int main(void) {

int rate=20;

double total=100;

char category;

printf("Enter the letter of your category");

scanf("%c",&category);

if(category=='M')

{

rate=rate+1;

total=rate*2;

}

else if(category=='F')

{

total=rate*2;

}

else

{

total=total+rate;

}

printf(" Final value of total %f",total);

printf(" Final value of rate %d",rate);

return 0;

}

Output: