Respuesta :
Answer:
// here is program in C.
#include <stdio.h>
//main function
int main(void) {
// variables
char type;
int gallon;
double tot_cost=0;
printf("Enter the type of customer(B for business or R for residential):");
// read the type of customer
scanf("%c",&type);
// if type is business
if(type=='b'||type=='B')
{
printf("please enter the number of gallons:");
// read the number of gallons
scanf("%d",&gallon);
// if number of gallons are less or equal to 8000
if(gallon<=8000)
{
// calculate cost
tot_cost =gallon*0.006;
printf("\ntotal cost is: $ %lf",tot_cost);
}
else
{
// if number of gallons is greater than 8000
// calculate cost
tot_cost=(8000*0.006)+((gallon-8000)*0.008);
printf("\ntotal cost is: $ %lf",tot_cost);
}
}
// if customer type is residential
else if(type=='r'||type=='R')
{
printf("please enter the number of gallons:");
// read the number of gallons
scanf("%d",&gallon);
// if number of gallons are less or equal to 6000
if(gallon<=6000)
{
// calculate cost
tot_cost=gallon*0.007;
printf("\ntotal cost is: $ %lf",tot_cost);
}
else
{// if number of gallons is greater than 6000
// calculate cost
tot_cost=(6000*0.005)+((gallon-6000)*0.007);
printf("\ntotal cost is: $ %lf",tot_cost);
}
}
return 0;
}
Explanation:
Ask user to enter the type of customer and assign it to variable "type". If the customer type is business then read the number of gallons from user and assign it to variable "gallon". Then calculate cost of gallons, if gallons are less or equal to 8000 then multiply it with 0.006.And if gallons are greater than 8000, cost for first 8000 will be multiply by 0.006 and for rest gallons multiply with 0.008.Similarly if customer type is residential then for first 6000 gallons cost will be multiply by 0.005 and for rest it will multiply by 0.007. Then print the cost.
Output:
Enter the type of customer(B for business or R for residential):B
please enter the number of gallons:10000
total cost is: $ 64.000000