Why is this incorrect?

I thought I finally was understanding this C++ wizardry, but I guess not!
I am getting multiple error messages "expected unqualified id before else" and "charge" or "cout does not name a type. Here is my code thus 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
41
42
43
44
45
46
47
48
49
50
51
//Advanced25.cpp.dev Program that calculates and displays total people registered, total charges of registrants, and average price per registrant
//Created/revised by <Russell> on <3/1/2018


#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 = companyCounter + 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;
}
1
2
3
4
	if (numOfRegistrants <= 3){
	}
		chargePerCompany = (totalRegistrants) * rateOne;	
	}

You have an empty if statement, followed by unrelated code, and then you have an extra } followed by two lone "else if"s.

Delete line 31.

[Edited mistake]
Last edited on
as Ganado says you have the curly braces in wrong places

but also you have misspelled some of your variables

you have a lower case o instead of O in numOfRegistrants in one of the if statements and also

chargePercompany should have a capital c like you declared it chargePerCompany

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
49
50

#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 = companyCounter + 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;
}


now it should compile fine
Topic archived. No new replies allowed.