if statement help

I am working on a program that shows a persons water bill for a month. There needs to be a minimum of $16.67 per month and I can't get that part to work. The rest of it works fine. can someone help me? Here is my code so far.

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
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	//declare variables
	double reading1 = 0.0;
	double reading2 = 0.0;
	double gallonsUsed = 0.0;
	double totalCharge = 0.0;

	//enter meter readings
	cout << "Enter previous meter reading: ";
	cin >> reading1;
	cout << "Enter current meter reading: ";
	cin >> reading2;

	//subtract previous reading from current reading
	gallonsUsed = reading2 - reading1;
	cout << "gallonsUsed = " << gallonsUsed << endl;
	cout << fixed << setprecision(2) << endl;

	totalCharge = gallonsUsed / 1000 * 7;
	cout << "totalCharge = " << totalCharge << endl;

	//calculate the total charge
	if (gallonsUsed < 1000)
	{
		totalCharge = 16.67;
		cout << "totalCharge = " << totalCharge << endl;
	}
	else 
	{
		totalCharge = gallonsUsed / 1000 * 7;
	}

	system("pause");
	return 0;
} //end of mani() 
You've two things going on here.

One is the calculation of total charge on line 24.

then you do the same thing again on line 35.

I would delete lines 24 and 25.

Last edited on
Line 25 should be moved under line 35 so you can see the result of the calculation. Agree on deleting line 24.
thanks
Topic archived. No new replies allowed.