Results 1 to 4 of 4

Thread: I dont know whats wrong!

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    Ontario Canada
    Posts
    236

    Unhappy I dont know whats wrong!

    Hey all, i'm having trouble with a problem. I don't know whats wrong with my logic. If anyone could help me, it would be appreciated. Well the problem is in the file attached. The following is my code. Could someone please point out whats wrong?

    #include <fstream.h>
    #include <string>
    #include <math.h>
    #include <stdlib.h>

    int main()
    {
    ifstream fin ("gift1.in");
    ofstream fout ("gift1.out");
    int NP;
    fin >> NP;
    int splitamount, splitpeople, original[NP];
    int gain[NP];
    string names [NP];
    string host, person;

    for (int i=0; i<NP; i++)
    {
    fin >> names[i];
    gain[i]=0;
    }

    for (int j=0; j<NP; j++)
    {
    fin >> host >> splitamount >> splitpeople;
    for (int i=0; i<NP; i++)
    if (names[i] == host)
    {
    original [i] = splitamount;
    if (splitpeople != 0)
    gain[j] += (splitamount % splitpeople);
    else
    gain[j] = splitamount;
    }
    for (int i=0; i<splitpeople; i++)
    {
    fin >> person;
    for (int k=0; k<NP; k++)
    if (names[k] == person)
    gain[k] += static_cast<int>(floor(splitamount/splitpeople));
    }
    }
    for (int i=0; i<NP; i++)
    fout << names[i] << " " << gain[i]-original[i] << endl;

    return 0;
    }
    Attached Files Attached Files
    YL says:"Few are those who see with their own eyes and feel with their own hearts."(Einstein)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width