HomeWork Help Please!

So, here is the question:

Problem 3:
Coloured tickets
The student council in your school wants to organize a charity breakfast, and since older students are both wiser and richer, the members of council decide that the price of each ticket will be based on how many years you have been in the school. A first year student will buy a PINK ticket, a second year student will buy a GREEN ticket, a third year student will buy a RED ticket, and a fourth year student will buy an ORANGE ticket.

Assume that all tickets are sold. Each color of ticket is uniquely priced. Input the cost of a PINK, GREEN, RED, and ORANGE ticket (in that exact order). Input the exact amount of money to be raised by selling tickets. Output all combinations of tickets that produce exactly the desired amount to be raised. The combinations may appear in any order. Output the total number of combinations found. Output the smallest number of tickets to print to raise the desired amount so that the printing cost is minimized.


and I do not know how to even start the actuall code! Here is what i have done so 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
#include <iostream>
using namespace std;
int main () {

	int pink;
		int green;
		    int red;
		       int orange;

	int totalred=0;
	int totalgreen=0;
	int totalred=0;
	int totalorange=0; 

	int raise;

	cout<<"Cost of PINK tickets:"<<endl;
		cin>>pink;
		cout<<endl;
	cout<<"Cost of GREEN tickets:"<<endl;
		cin>>green;
		cout<<endl;
	cout<<"Cost of RED tickets:"<<endl;
		cin>>red;
		cout<<endl;
	cout<<"Cost of ORANGE tickets:"<<endl;
		cin>>orange;
		cout<<endl;

	cout<<"How much must be raised with ticket sales?"<<endl;
	cin>>raise;

	cout<<"Combinations are:"<<endl;

	//will i use a while statement? 

return 0;

}
Try working it out on paper with an example.
Assume the amount to be raised is $100 and the tickets are $4,$3,$2,$1 respectively. Clearly, you could sell 25 pink tickets or 100 orange tickets.
One way to do this would be to have 4 nested loops, each iterating through the possible number of each color ticket.
1
2
3
4
5
6
7
8
9
10
11
12
for (int pink=raise; pink>= 0; pink--)
{  for (int green=raise; green >= 0; green--)
    { for (int red=raise; red >= 0; red--)
       { for (int orange=raise; orange >= 0; orange--)
          {  // calculate how much this combination of tickets raises
              // Does it match the desired amount?
              // if so, print out the combination
              // Is this the fewest number of tickets to print?
          }
       }
    }
}

There are ways to optimize this, but this will get you there. .

Topic archived. No new replies allowed.