Mine crashes @line 52 when the program tries to divide by zero.
Since it's in my computer...
Remove the #include <cstdlib>
Add: #include <iomanip> and you will get better formatting options:
Try: outfile << right << setw(14) << i << setw(22) << batches[i] << setw(18) << chocolates[i] << endl;
and outfile << right << setw(14) << n << setw(32) << averages[n] << endl;
"right" right justifies the text, setw(n) gives the text that much space to be written. Tabs are trouble with differing length outputs
I just checked the entire data file and I don't see a 13 in the first column so that's probably the problem...
I guess the best way to fix this would be to just put a check if batches ever == 0 then continue with the loop from the start?
EDIT: How did you know it was trying to divide by zero? Did you just carefully examine the code or did you use some debugger?
EDIT#2: I set a check for batches[i] == 0 and it works fine now... Thanks for the help
Also... the reason I included <cstdlib> is because I use the exit(0) function if the program fails to open the data file. If I remove that, exit(0); won't work. Is their another way to shut down the program if the data file does not open?