Please help me on this.
Nov 19, 2011 at 4:47am UTC
i supposed to output 10 students last name and first and the their 10 grades and each of their average grades. My program doesn't output anything on the screen. What have i done wrong. please help me.
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
void avgCalculation(ifstream& in_file, ofstream& out_file);
int main()
{
ifstream fin;
ofstream fout;
fin.open("grades.dat" );
if (fin.fail())
{
cout<<"Input file opening failed" <<endl;
exit(1);
}
fout.open("grades.dat" );
if (fout.fail())
{
cout<<"Output file opening failed" <<endl;
exit(1);
}
avgCalculation(fin, fout);
fin.close();
fout.close();
// cout<<"End of program"<<endl;
return 0;
}
void avgCalculation(ifstream& fin, ofstream& fout)
{
int i, sum, total[10];
int const ten = 10;
string first, last;
double avg;
while (fin>>last)
{
fin>>first;
sum = 0;
for (i = 0; i<10; i++)
{
fin>>total[i];
sum = sum + total[i];
}
avg = static_cast <double >(sum)/ten;
fout<<last;
fout<<" " ;
fout<<first;
fout<<" " ;
for (int l = 0; l<10; l++)
{
fout<<total[l];
fout<<" " ;
}
fout<<avg;
fout<<endl;
}
}
Nov 19, 2011 at 6:08am UTC
thats because you are outputing to the file only
line 33 is the only one that can print in the compilier window
but you have commented out.
Topic archived. No new replies allowed.