Help With Program Unsure of What is Wrong

Hello everyone. SO recently, I have been taking a look at the USACO training pages. I did not know that even the easiest programs were difficult for me. Anyways, I was working on Greedy Gift Givers, the second problem in the list and was kinda stuck about how to do the actual calculations. I could get the input down but the calculations were hard. Because many people on the web have already done this program, I decided to look at some of the code. I took a bit of help from this website, which is why the code looks very similar, but when run my program it does not print out correct answers. It is WHACKY! Here is the website for the problem as well as the code I received help from regarding calculations. My code is posted below and i would really appreciate if you could decipher the problem or give me a hint as t where the problem lies. And one more question: the website with the code that i received help used break statements in the if statemtents. WHY? Why couldnt the person put the next lines inside the statement? Thank you so much. :)

http://usacotraining.blogspot.com/2013/09/problem-112-greedy-gift-givers.html

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  #include <iostream>
#include <fstream>
#include <string>
using namespace std;


//create function that generates profit


int main()
{

   // ofstream fout ("gift1.out");
   //ifstream fin ("gift1.in");

   int x, y, i, people, numofreceivers, imoney, account[10], initial[10];
   string group[10], giver, receivers;

   cin >> people;

   for (int x = 0; x < people; x++)
   {
       cin >> group[x];
       account[x] = 0;
   }


   for (int x = 0; x < people; x++)
   {
       cin >> giver;
       cin >> imoney >> numofreceivers;

       for (y = 0; y < people; y++)
       {
           if (group[y] == giver)
           {
             break;
           }

       }
           account[y] = account[y] + imoney - ((int)(imoney/numofreceivers) * imoney);
           initial[y] = imoney;

       for (y = 0; y < numofreceivers; y++)
       {
           cin >> receivers;

           for (i = 0; i < people; i++)
           {

                if (group[i] == receivers)
              {
                break;
              }

           }

            account[i] += (int)(initial[y] / numofreceivers);
       }

   }

    for (int p = 0; p < people; p++)

    {
        cout << group[p] << " " << (account[p] - initial[p]) << endl;
    }

    return 0;
}
Topic archived. No new replies allowed.