So I have a task which i have to
"calculate a monthly electricity bill, a standing charge of €20 is added to
a charge of €0.05 per unit of electricity used. The number of units used is
based on the difference between a previous and present meter reading.
The meter has a maximum reading of 9999, after which it returns to 0000.
Write a program that will accept as input a pair of values representing the
previous and present meter readings respectively. The program should
then calculate and display an electricity bill. Allow for the fact that the
previous meter reading may be greater than the present reading if the
meter has passed 9999 and returned to 0000. Assume that 10000 units of
electricity will never be used in one month."
My if else statement is not working if you could take a look what I am doing wrong because I cannot see anything at all wrong with it.
I also included <iostream> in stdafx.h
using namespace std;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
int main()
{
double standingCharge = 20.00;
int presentMeterReading;
int previousMeterReading;
double unitPrice = 0.05;
int unitsUsed;
double unitCharge;
double totalCharge;
cout << "Please enter the previous meter reading on your meter : ";
cin >> previousMeterReading;
cout << "\n\n";
cout << "Please enter the present meter reading on your meter : ";
cin >> presentMeterReading;
cout << "\n\n";
if (previousMeterReading < presentMeterReading)
{
unitsUsed = presentMeterReading - previousMeterReading;
}
else (previousMeterReading > presentMeterReading);
{
unitsUsed = 10000 + presentMeterReading - previousMeterReading;
}
cout << "The total units of electiricty you used this month : " << unitsUsed;
cout << "\n\n";
unitCharge = unitsUsed * unitPrice;
totalCharge = unitCharge + standingCharge;
cout << "The unit price is 0.05c and there is a 20 euro standing charge.";
cout << "\n\n";
cout << "The total cost of your electricty bill comes to " << totalCharge;
cout << "\n\n";
|
The problem is the calculations in the If else statement but they look perfectly fine, this is what outputs on the command prompt below.
Please enter the previous meter reading on your meter : 8000
Please enter the present meter reading on your meter : 9000
The total units of electricty you used this month : 11000
or
Please enter the previous meter reading on your meter : 0100
Please enter the present meter reading on your meter : 9000
The total units of electricty you used this month : 18900