Dec 9, 2017 at 3:54am UTC
It isn't letting me write to the file that i need to. what am i doing wrong?
Dec 9, 2017 at 5:34am UTC
You should fill the array BEFORE saving the file. I see no cin >> scores[i][j] anywhere. Also, you seemed to have flipped the variables in the scores definition from int scores[STUDENTS][TESTS] to int scores[tests][students]. First, you had 5 groups of 3, now you have 3 groups of 5.
Dec 9, 2017 at 5:37am UTC
Where would a cin>> go? i thought thats what the outputFile<<scores did in the loop? and when am i saving the file in here?
Dec 9, 2017 at 5:52am UTC
oh ok, that makes sense. Would i just put that loop after i ask them to enter the scores? I tried that and it gave me an odd error
Dec 9, 2017 at 5:58am UTC
@jpengineer
You should ask for the scores, and fill them, BEFORE you request the filename, open and save the file.
ie:
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
cout<<"Please enter the scores:" ;
for (int i = 0; i<students; i++)
{
for (int j = 0; j < tests; j++)
{
cin >> scores[i][j] << " " ;
}
}
ofstream outputFile;
cout<<"Please enter the file name: " ;
cin >> filename;
outputFile.open(filename);
for (int i = 0; i<students; i++)
{
for (int j = 0; j < tests; j++)
{
outputFile << scores[i][j] << " " ;
}
outputFile << endl;
}
outputFile.close();
Last edited on Dec 9, 2017 at 6:00am UTC