Write C program that calculates the water bill. Please use if else statments. Wr
ID: 3883238 • Letter: W
Question
Write C program that calculates the water bill. Please use if else statments.
Write a C program that calculates the water bill according to the chart below. The program should let a user enter the user type and the water usage amount and then displays the total cost (including tax). See sample code execution. Red is entered by a user Sample Code Execution #1 Enter User Type (R for Residential, B for Business): E Enter water usage in cubic feet: 58 Wrong User Type Sample Code Execution #2 Enter User Type (R for Residential, B for Business): R Enter water usage in cubic feet: 58.5 Total cost including tax is $10.67Explanation / Answer
#include <stdio.h>
int main()
{
char type;
int waterFeet;
double cost, fixedCost, feetCost;
const double PERCENTAGE = 6.1;
printf("Enter User Type (R for Residential and B for Business): ");
scanf("%c", &type);
printf("Enter water uage in cube feet: ");
scanf("%d", &waterFeet);
if(type == 'R') {
fixedCost=9.00;
if(waterFeet <= 700) {
feetCost = 0.018;
} else if(waterFeet > 700 && waterFeet <= 1500) {
feetCost = 0.032;
} else {
feetCost = 0.08;
}
cost = fixedCost + feetCost * waterFeet;
cost = cost + (cost * PERCENTAGE)/100;
printf("Total cost including tax is $%.1lf ", cost);
} else if(type == 'B') {
fixedCost=14.00;
feetCost = 0.0288;
cost = fixedCost + feetCost * waterFeet;
cost = cost + (cost * PERCENTAGE)/100;
printf("Total cost including tax is $%.1lf ", cost);
} else {
printf("Wrong User Type ");
}
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.