You are on page 1of 1

Practical 4 Q3

#include <stdio.h>
int main ()
{
char code;
float price, commission, rate;
printf
printf
printf
printf

("\t\t\t\t
("\t\t\t\t
("\t\t\t\t
("\t\t\t\t

Transaction
S - Rate is
M - Rate is
L - Rate is

Code: \n\n");
5%% \n");
7%% \n");
10%% \n\n\n");

printf ("Please enter the transaction code\n>>");


scanf("%c", &code);
printf("\nPlease enter the retail price\n>>");
scanf("%f", &price);
switch(code)
{
//char need single quotation
case 'S':
rate = 0.05;
break;
case 'M':
rate = 0.07;
break;
case 'L':
rate = 0.1;
break;
//Default - used when there is none of the above.
default:
rate = 0;
printf("Invalid Transaction Code :( \n");
}
commission = rate * price;
printf("Commission is RM%.2f \n", commission);
return 0;
}

You might also like