i have a code with algo that fits my problem, but i get this error message when i compile it.. #8 floating point exception [usually caused by accessing memory out of bounds]. who knows what's this?
here is my code
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ofstream fout ("gift1.out");
ifstream fin ("gift1.in");
int a;
fin>>a;
string S[a];
int b[a];
int totalmoney,totalperson,moneyperperson;
for(int i=0;i<a;i++)
{
fin>>S[i];
b[i]=0;
}
string buffer;
for(int l=0;l<a;l++)
{
fin>>buffer;
for(int i=0;i<a;i++)
{
if(buffer==S[i])
{
fin>>totalmoney;
fin>>totalperson;
moneyperperson=totalmoney/totalperson;
b[i]=b[i]-totalmoney+(totalmoney%totalperson);
for(int j=1;j<=totalperson;j++)
{
fin>>buffer;
for(int k=0;k<a;k++)
{
if(buffer==S[k])
b[k]+=moneyperperson;
}
}
break;
}
}
}
for(int i=0;i<a;i++)
fout<<S[i]<<" "<<b[i]<<endl;
return 0;
}