cotegory that might be entered by a user, indicate the final values for rate and
ID: 3870558 • Letter: C
Question
cotegory that might be entered by a user, indicate the final values for rate and total int rate 20: double total 100.Q char category: Orinte.s Ehger the letter of your category: " printf Enter scanfC" c", &category; switch(category) case 'M' :rate rate 1; case ‘F' : total-rate * 2; case 'H: break; case o': rate (int) (total)/8): break; default total total rate; break; Final value of rate is: Final value of total is: Sample value for 6. Write a comparable if-else statement for the switch statement above (just start at the beginning of switch) Assume the following if-statement is part of some code: What would be the minimum set of test cases for this expression? 7, if ( avg 75 && avg = Test value for Reason Expected result Actual Result (Leave Blank)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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.