In: Computer Science
make a C++ program to calculate total water bill for a customer. The water company charges $250.00 for <=1000 gallons of water. Over 1000 gallons the company charges .99 / gallons
The program displays
Gallons of water used = xx
Exatra payment= xx
Total payment = xx
code:
#include <iostream>
using namespace std;
int main() {
int n;
float p=250.00,e; // Initially the payment value will be 250
cout << "Gallons of water used ="; // Inputs the
gallons
cin >> n; // stores in the variable n
if(n<0) // if user enters n value less than 0 then p will be
0
p=0;
if (n>1000){ // if the gallons > 1000, the payment will be
.99/gallon more to 250
p=250.00+(n-1000)*0.99;
e=p-250.00; // varibale stores the extra payment
}
cout << "Extra payment = " << e << endl;
cout << "Total payment = " << p;
return 0;
}
Note:
* Here in second if, the condition is n>1000. And there is no code for n<=1000. For that the p value will be the default value 250 which is already declared.
outputs:
Gallons less than 1000
Gallons more than 1000
Thankyou