Answer:
#include <bits/stdc++.h>
using namespace std;
int main()
{
// variables
char cust_t;
int no_gallon;
double cost=0;
cout<<"Enter the type of customer(B for business or R for residential):";
// read the type of customer
cin>>cust_t;
// if type is business
if(cust_t=='b'||cust_t=='B')
{
cout<<"please enter the number of gallons:";
// read the number of gallons
cin>>no_gallon;
// if number of gallons are less or equal to 8000
if(no_gallon<=8000)
{
// calculate cost
cost=no_gallon*0.006;
cout<<"total cost is: $"<<cost<<endl;
}
else
{
// if number of gallons is greater than 8000
// calculate cost
cost=(8000*0.006)+((no_gallon-8000)*0.008);
cout<<"total cost is: $"<<cost<<endl;
}
}
// if customer type is residential
else if(cust_t=='r'||cust_t=='R')
{
cout<<"please enter the number of gallons:";
// read the number of gallons
cin>>no_gallon;
// if number of gallons are less or equal to 8000
if(no_gallon<=8000)
{
// calculate cost
cost=no_gallon*0.007;
cout<<"total cost is: $"<<cost<<endl;
}
else
{// if number of gallons is greater than 8000
// calculate cost
cost=(8000*0.005)+((no_gallon-8000)*0.007);
cout<<"total cost is: $"<<cost<<endl;
}
}
return 0;
}
Explanation:
Ask user to enter the type of customer and assign it to variable "cust_t". If the customer type is business then read the number of gallons from user and assign it to variable "no_gallon". Then calculate cost of gallons, if gallons are less or equal to 800 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 8000 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:9000
total cost is: $56