Assignment hlep regarding while loop and a a bell curve

What I need to do is use either a while or for loop to demonstrate a bell curve, and then find the maximum amount of profit and said profit's corresponding ticket price and passenger amount.

To do this we were given this equation.

NP is the Number of Passengers
TP is the Proposed Ticket Price
MP is the Minimum Number of Passengers

Cost of Ticket = TP - (((NP - MP) /10) * .5)
Profit = (NP * Cost of Ticket) - 2500


The issue I'm having is every time I punch in the values I get a fixed climb, and it results in the maximum amount of people being the best choice for profit. I get the feeling I've made a terrible mistake somewhere, but I just can't seem to find it. Or even worse, this being a math issue and not a programming one...


I apologize for the sloppy output, but I just wanted to make sure I could get this working before I go any further.
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
#include<conio.h>
#include<iomanip>
#include<iostream>
using namespace std;

int main()
{
//NP=max number of people,  MP=minimum number of people. TP=proposed ticket price.  
int count, NP, MP, bestPass;
float high, TP, ticketCost, profit, bestPrice;


	cin>> NP;
	cin>> MP;
	cin>> TP;

	count = MP;
	while (count <= NP)
	{
		MP = count;
		ticketCost = TP - (((NP - MP) /10) * 0.5);
		profit = (NP * ticketCost) - 2500;

		if(high < profit)
		{
			high = profit;
			bestPrice = ticketCost;
			bestPass = MP;	

		}	   	   
	  	  	  
		cout<< profit << " ";
		count+=10;
	   	   	   	      	   	   
	}

cout<< "\n\n" << high;
cout<< "\n" << bestPrice;
cout<< "\n" << bestPass;
	

	
return 0;
}

 


Last edited on
Topic archived. No new replies allowed.