HELP! Is this correct? 5. Read the following code. For each of the provided exam
ID: 3871345 • Letter: H
Question
HELP! Is this correct? 5. 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 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; (int) (total ) /8) ; rate break; ‘D' : = case default : total= total + rate; break; Final valuc of total is Final value of rate is: Sample valuc for category H' haua liust start at the beginning ofExplanation / Answer
In case of M final rate value is 21 and final total is 100.00000
In case of H final rate value is 20 and final total is 100.00000
In case of G final rate value is 20 and final total is 120.00000
These are values when you execute the program.
Actually if break is not there in Case of 'M' so it prints both the M and F values.
For your clarification i have executed the program and submitting you check it once.
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
int main()
{
int rate=20;
double total=100.0;
char category;
printf("enter category ");
scanf("%c",&category);
switch(category)
{
case 'M' : rate = rate+1;
printf("M case total %lf ",total);
printf("M case rate value %d ",rate);
case 'F' : total=rate*2;
printf("F case total %lf ",total);
printf("F case rate value %d ",rate);
break;
case 'H' : printf("H case total %lf ",total);
printf("H case rate value %d ",rate);
case 'D' : rate = (int)(total)/8;
printf("D case total %lf ",total);
printf("D case rate value %d ",rate);
break;
default : total=total+rate;
printf("default case total %lf ",total);
printf("default case rate value %d ",rate);
break;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.