just finished my C++ homework assignments, the second one was really good, its the first one that i actually had to plan and think on.
i had to write a program that calculates the amount of gallons of water used and the price of the water bill using two meter readings, with the base price being 16.67, plus 7 for every 1000 gallons used~.
i'm so proud of myself~~ and i didnt even need an IPO chart =D.
Code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double currentRead = 0.0;
double prevRead = 0.0;
double gallonsUsed = 0.0;
double totalCharge = 0.0;
const double CHARGE = 7.0;
const double BASE_CHARGE = 16.67;
//enter inputs
cout << "Please enter the current meter reading: ";
cin >> currentRead;
cout << "Please enter the previous meter reading: ";
cin >> prevRead;
//calculate gallonsUsed
gallonsUsed = currentRead - prevRead;
//if statement
if (gallonsUsed > 1000)
{
double extraCharge = 0.0;
//if more than 1000 gallons were used
extraCharge = gallonsUsed / 1000;
totalCharge = extraCharge * CHARGE + BASE_CHARGE;
cout << "Number of Gallons of water used: " << gallonsUsed << endl;
cout << "Total water charge: $" << fixed << setprecision(2) << totalCharge << endl;
}
else
{
cout << "Number of gallons of water used: " << gallonsUsed << endl;
cout << "Total water charge: $" << fixed << setprecision(2) << BASE_CHARGE << endl;
} //endif
return 0;
} //end of main function
edit: the only thing is that if it was a workout for me, then for a good bit of the rest of the class its "holy *** ***omgwtfidontknowthisisimpossible" =/
i'll be expecting lots of calls between now and the due date =/