C++ Would someone take a look at my code to see what is wrong.

Would someone mind to take a look at my code to see what is wrong. I need a program should allow the sales manager to enter the number of registrants for as many companies as needed. When the sales manager has finished entering the data, the program should calculate and display the total number of people registered, the total charges for those registrants, and the average charge per registrants.

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
#include <iostream>
#include <iomanip>

using namespace std;
int main()
{
	//declare variables

	const int rate_123 = 150;
	const int rate_429 = 100;
	const int rate_10  = 90;
	int reg = 0;
	int numReg = 0;
	int totalReg = 0;
	int company = 0;
	int avg = 0;
	int totalCharges = 0;
	
	//Enter values
	cout << "How many people are registering: ";
	cin >> reg;

	// Calculate
	while (numReg >= 0)
	{
		totalReg += numReg;
			
	}
	//end while
if (numReg < 4);
			{
				company = numReg * rate_123;
			}
	else if (numReg < 10 && numReg > 3);
			{
				company = numReg * rate_429;
			}
	else 
				company = numReg * rate_10;


	//calculate
			totalCharges += company;
			avg = static_cast<double>(totalCharges)/totalReg;
			cout << "Total number of people registered: " << totalReg << endl;
			cout << "Total charges for people registered: " << totalCharges << endl;
			cout << "Average amount: " << avg << endl;

system("pause");
return 0;
//end of main function 
1
2
3
4
5
	while (numReg >= 0)
	{
		totalReg += numReg;
			
	}


When will this while loop finish?
Diana,

Actually I think your code is really far from meeting its requirements. It's not in the state to point WHAT is wrong. Did you review the code yourself? The loop, per example, doesn't make sense. Try getting the "totalReg += numReg;" out of this while block. The line inside the while block will never change the loop condition, resulting in a never ending loop.

Also, reg is being assigned, but never being used. You probably should put the input on the numReg variable instead of reg, and just get rid of reg.

You have some useless variables. Maybe I didn't understand the requirements, apart from this code looking like a homework "Complete the code..." style.
Last edited on
Topic archived. No new replies allowed.