Nested Loop Help

I am tasked to write a program that displays the cost of a medical conference, the total number of people, and the cost per person, given the number of people. I need to be able to add more people on as I go, and I must use a sentinel. I am stuck figuring out exactly which loop to nest. I am given the cost per person for certain ranges, so for a couple people, its a certain cost, for slightly more people, its a little less and so on. I attempted using a switch, but I am realizing that probably wont work.

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
#include "stdafx.h" // loads precompiled header
#include <iostream> // allows input and output

using namespace std; //allows all names in standard directive

// Function main begins execution
int main()
{
	
	double cost = 0;
	int people = 0;
	cout << "How many people are attending the conference?\n";
	
	top:
	for (int count = 0; count != -1; count = count + people)
	{
		cin >> people;
		
		switch (people)		
		{
		case 1:
		case 2:
		case 3: 
			cost = 129.50;
			break; 
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
		case 9:
		case 10:
			cost = 110.50;
			break;
		default: 
			cout << "Please enter a valid integer";
			goto top;
			break;
		}

		double total = count * people;
		cout << "The conference will cost $" << total << " with " << count << " people at $" << cost << " per person.\n\n";
		cout << "Enter the number of additional participants.\nEnter -5 to end the program.\n";
Add in additional else if statements for however many costs you have.

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

int main(void)
{
	double cost, totalcost, arbitrarycost, arbitrarycost2, arbitrarycost3;
	int people;
	char ans;
	int arbitrarynumber;

	while (ans == 'y' || ans == 'Y')
	{
		std::cout << "How many people will be attending?: \n";
		std::cin >> people;

		if (people <= arbitrarynumber)
		{
			totalcost = (people * arbitrarycost);
		}
		else if (people > arbitrarycost2 && people <= arbitrarycost3)
		{
			//Same thing as above, different numbers.
		}

		std::cout << "The total cost for " << people << " will be: " << totalcost;
		std::cout << "\nWould you like to continue? (y/n)\n";
		std::cin >> ans;
	}
	return 0;
}
Everything worked great! Thank you so much for your help! There's only one thing I can't figure out at this point: why when using fixed precision are only my answers for 1,2, or 3 attendees (count) returning an answer for "cost" in scientific notation. ie a count of 1 returns an answer for cost as 1.3e+002 rather than 129.50.

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 "stdafx.h" // loads precompiled header
#include <iostream> // allows input and output

using namespace std; //allows all names in standard directive

// Function main begins execution
int main()
{
	
	double cost = 0; // total cost 
	double costpp = 0; // cost per person
	int count = 0; // total number of attendees
	int people = 0; // number of people from an individual group
	char ans = 'y'; // sentinel to prompt action

	cout << "Welcome to the Conference Cost Calculator!\nYou can add more attendees by choosing to continue when prompted\n";

	while (ans == 'y' || ans == 'Y') // loop will continue if "Y" or "y" is entered
	{
		cout << "How many people will be attending? \n\n"; 
		cin >> people; // prompts input
		count = count + people; // counter to total attendees

		// if statements to determine the total cost based on the count
		if (count >= 11)
		{
			cost = (count * 84.00);
		}
		
		else if (count >= 4 && count <= 10)
		{
			cost = (count * 110.50);
		}

		else if (count >= 1 && count <= 3)
		{
			cost = (count * 129.50);
		}

		double costpp = cost / count; // calculates cost per person
		
		cout.precision(2); // answers in 2 decimal places with "fixed"

		cout << "\nThe conference will cost $" << cost << fixed << " with " << count << " people at $" << costpp << fixed << " per person.\n\n"; // displays answers
		cout << "Would you like to continue to add more attendees? (y/n)\n\n"; // asks user for loop decision
		cin >> ans; // loop decision
		cout << "\n\n"; // skips a line

	} // end while loop
} // end function main 
Topic archived. No new replies allowed.