Help, Using input to define 3 variables.

Hello,

I am stuck on a problem I cannot figure out.

For the problem I need to use input from the user (A number value which is how much gold they wish to spend) to find out the quantity of 3 different items they can purchase.

The specifics is the user inputs how much gold they wish to spend and then the program finds all the possible combinations of the 3 items quantities that equate to the input. After it displays the results the program needs to display a count of how many combinations there were. ie, If 50 gold is input, the program will display something like "you can purchase 4 pins 8 feathers and 16 glasses" where each item has a gold value different from eachother. Where that could be one combination, and the program will display all possible combinations of the items which equate to 50 gold.

Im not looking for getting it specifically answered as I would like to work it out on my own as it helps understanding, but if anyone can point me in the right direction, or let me know what type of functions i should be using, Arrays? Recursive Functions?

I cannot for the life of me figure out how to even display one combination, yet alone a list of possible combinations.

Any help is appreciated.
Last edited on
If anyone knew how I could handle this problem, I'd appreciate it.
Have you tried anything yet? If so post the code please.
I have tried a few things but they are so far off it. I am completely new to C++, and have no idea how to even go about solving this problem. I would just like to know how I should be going about this problem, what I should be learning and how I can put it all toghether.

Thanks.
Hopefully this can get you started.
1
2
3
4
5
int gold;
cin >> gold;
cout << "pins="<<gold/pricePin<<endl;
cout <<"feathers= "<<gold/priceFeather<<endl;
//etc.. 
Last edited on
I see,
And the prices of pins, feathers and glasses are dependant on one another, Ie if gold=50, pins would be something like gold/pricePin - gold/priceFeather?

I first need to find how to check if the 3 totals = goldInput and maybe a recursive function to run through every possibility to see if the total matches the goldInput and if so, display result, if not don't display.
I was assuming the prices of the items are known and set, you can find how many you can buy with integer division of gold, for each item. But I think I missed your initial problem, if you want to find all combinations of items to say maximize value research bin packing algorithms.
Last edited on
bin packing algorithms got it, thank you.
Topic archived. No new replies allowed.