Program, array problem

Hi,
I am a beginer in C++. I'm doing a program which made me frustrating.
The object is to create a program which should calculate the best way to buy items (like socks).
Data:
In one box there is 144 socks. In the bundle of socks there are 12 socks.
The input data:
720(amount of socks we want to buy), 303(price of a box), 32(price of a bundle), 3(price of unit).

So here I have to make a program that decides how many boxes, bundles, or units to buy for the best results (of course we want as many and as cheaper as we can get.)
e.q.
We want 355 socks
price of a box - 292
price of a bundle - 49
price of an unit - 6
Results:
Bought -
Boxes: 2
Bundles: 5
Units: 7
Explanation - Buying boxes are the cheapest and most profitable way to buy, but we can't buy 3 boxes at a time because^:
(3(boxes) * 144(amount of socks in the box)) > 355(number of socks we want)
so we buy bundles and so on...
What I tried to do is to find on the witch situation unit of a sock would cost cheapest.


My object is to find the biggest value (there is a problem in the code) and if it is, try to use it e.q. box = box + 1; as far as it is possible (aren't more than the number we want to buy^). I don't know if everything is clear to you guys, but if it is please help it would be very appreciated if you include comment lines to argument why you did one or another thing, because I really want to learn things like that.
Cheers.
//Sorry for my bad English.
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 <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main(){
    int k; //k - the amount of socks we want to buy
    int sd, sr;
    /*
    sr - number of socks in the bundle
    sd - number of socks in the box
    */
    int box, bundle, unit, var1, var2, var3;
    sd = 12 * 12;
    sr = 12;

    cout << "Input prices of: box, bundle, unit: " << '\n' ;
    cin >> box; //retrieving price of a box
    cin >> bundle; //retrieving price of a bundle
    cin >> unit; //retrieving price of a unit
    cout << "Input number of the unit we want to buy: " << '\n' ;
    cin >> k; // number of socks we want to buy
    cout << "                                 " << endl; //not practical, don't pay attention
    var1 = k / unit; //finding how many unit could I buy
    var2 = k / bundle * sr; //finding how many bundles could I buy
    var3 = k / box * sd; //finding how many boxes could I buy
    cout << "amount of socks we can buy by choosing units:" << '\n' << setw(18) << fixed << var1 << endl;
    cout << "amount of socks we can buy by choosing bundles:" << '\n' << setw(18) << fixed << var2 << endl;
    cout << "amount of socks we can buy by choosing boxes:" << '\n' << setw(18) << fixed << var3 << endl;
    // I think the more we can buy the better, more profitable it is
    // Finding the biggest value, here it is a problem
   /*
int array[3] = {var1, var2, var3};
    int nbox = 0, nbundle = 0, units = 0; //number of unit we buy (boxes, bundles or units)
    for(int i=0;i<3;i++)
    {
        if(array[1] > array[2] || array [3])
        nbox = k / sd;
        cout << nbox << endl;
        else if(array[2] > array[1] || array [3])
        nbundle = k / sr;
        cout << nbundle << endl;
        */
//undone
    }
Topic archived. No new replies allowed.