I am a novice coder and I am currently working on the Usaco Training problems to improve my skills. This was my code for "Greedy Gift Givers". When I submit the code, I get an error that says: Execution error: Your program (`gift1') exited with signal #8 (floating point exception [usually caused by accessing memory out of bounds]). The program ran for 0.000 CPU seconds before the signal. It used 3504 KB of memory. " I have been looking through my code and trying to fix this error for a while now. Can anyone help? Please don't get angry with me as this is my first time posting, and like I said, I'm brand new to programming.
/*
ID: ashton.1
PROG: gift1
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream fin ("gift1.in");
ofstream fout ("gift1.out");
int initial, account[10], recipients, NP;
string names[10], giver, receiver;
fin >> NP;
for (int k = 0; k < NP; k++)
{
fin >> names[k];
account[k] = 0;
}
for (int k = 0; k < NP; k++)
{
fin >> giver >> initial >> recipients;
for (int y = 0; y < NP; y++)
{
if( names[y] == giver)
break;
}
account[k] -= initial;
account[k] += initial % recipients;
for (int y = 0; y < recipients; y++)
{
fin >> receiver;
for (int j = 0; j < NP; j++)
{
if(names[j] == receiver)
break;
}
if(recipients != 0)
{
for(int x = 0; x < NP; x++)
{
account[x] += (int)initial / recipients;
}
}
}
fout << names[k] << " " << account[k] << endl;
}
return 0;
}