Thanks! One more issue

Alright! The only issue I am having with the program now is that it isn't working as it should. 1 through 3 registrants should be 150 per. 4 through 9 should be 100 per and 10 and up should be 90 per. It is charging 150 for every ticket no matter what.

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

int main()
{
	//declare variables
	int numOfRegistrants = 0;
	int totalRegistrants = 0;
	int companyCounter = 0;
	const double rateOne = 150.00;
	const double rateTwo = 100.00;
	const double rateThree = 90.00;
	double chargePerCompany = 0.00;
	double totalCharge = 0.00;
	double averageCharge = 0.0;

	cout << "Enter amount of company's registrants: ";
	cin >> numOfRegistrants;
	while (numOfRegistrants >= 0){
		totalRegistrants = totalRegistrants + numOfRegistrants;
		companyCounter += 1;;
		cout << "Enter amount of next company's registrants (or negative number to stop): ";
		cin >> numOfRegistrants;
	}	//end while
	if (numOfRegistrants <= 3){

		chargePerCompany = (totalRegistrants) * rateOne;
	}
	else if(numOfRegistrants <= 9){
		chargePerCompany = (totalRegistrants) * rateTwo;
	}else if(numOfRegistrants >= 10){
		chargePerCompany = (totalRegistrants) * rateThree;
	}
	//end ifs

	totalCharge = chargePerCompany;

	averageCharge = totalCharge / totalRegistrants;

	//display the data
	cout << fixed << setprecision (2) << endl;
	cout << "Total people registered: " << totalRegistrants << endl;
	cout << "Grand total charges: $" << totalCharge << endl;
	cout << "Average charge per registrant: $" << averageCharge << endl;

	return 0;
}
companyCounter is not being used?
Have you tried stepping through it with a debugger, to find out exactly what the values of the variables are at each step in the execution of the program?
Q: What do we know about numOfRegistrants after line 25 (i.e. when the loop is over)?
A: That numOfRegistrants >= 0 is false.

Q: Which branch of the if else .. is selected, when numOfRegistrants < 0?
A: Is that really the way the program should decide?
Topic archived. No new replies allowed.