omputer Engineering Department Laboratory Acti vity Form Course Number ES084 Course Title Computer Programming 1 Topios Covered: Switch and if-else if selection structure Implement a program using (oombine the use of) the if-else if and switoho seleotion structure. Objecti ves: Desoription W rite a program thatwill oaloulate and print out bils for the oity water oompany. The water rates vary depending on whetherthe water s for home use, commeroial use or industrial us e. A code of H/h means home use, a oode of C/o means oommeroial use and a code of /i means industrial us e. The water rates are computed as tollows: 0ode H/h: P250.00 plus PO.002 pergallon used 0ode C/o: P5,000.00 forthe first 4 million gallons and PO.002 foreach additional gallon. P8,000 if us age does not exoeed 4 million gallons, P14,000 if us age is more than 4 million gallons but not more that 10 million gallons and P18000 if us age exoeeds 10 million gallons. oode l/: Your program should prompt the user for the oode and the gallons of water used. Your programshould echo your input data and should print the amount due from the user. Your program should use a switoh statementfor the oode (ohar data type). Use the flo at data type for the gallons. Sample Output it Applicable Z: VCCS121G4U.13302-1\EXER13.EXE pata Code -Induitri Enput dath code Irput number of water Cin gallons) uredi S67007 TOTAL COST IS S000.00 Remarks Filename : EXER2_6.C Lab. InstruotorTeacher:Roel B. Lauron
#include<stdio.h>
#include<math.h>
int main()
{
char cod;
int gal;
float cost;
printf("Data Codes:");
printf(" \n H-Home \n C-Commercial \n I-Industrial ");
printf("\nInput data code: ");
scanf("%c", &cod);
printf("\nInput number of water (in gallons) used: ");
scanf("%d", &gal);
if (cod=='H'|| cod=='h')
{
cost = 250+(0.002*gal);
printf("\nTOTAL COST IS %.2f", cost);
}
else if (cod=='C'||cod=='c')
{
if (gal<=4000000)
{
printf("\nTOTAL COST IS 5000.00");
}
else
{
cost = 5000*((gal-4000000)*0.002);
printf ("\nTOTAL COST IS %.2f", cost);
}
}
else if (cod=='I'||cod=='i')
{
if (gal<=4000000)
{
printf("\nTOTAL COST IS 8000.00");
}
else if (gal>=4000000 && gal<=10000000)
{
printf("\nTOTAL COST IS 14000.00 ");
}
else if (gal>10000000)
{
printf("\nTOTAL COST IS 18000.00 ");
}
}
else
{
printf ("\nINVALID DATA CODE");
}
}
I already have this but i dont know how to use switch


Step by step
Solved in 2 steps









