Ok, i was told to make a program which reads number grades from an input file, saves them to an array, finds out the largest grade, the number of grades, then gets the grades individually and finds the curved grade and prints them to an output file.
My problem is that i do all this, it compiles with 0 errors but an error still occurs when i try to run it, also, in the output file, only one of the curved grades comes out, here is the program so far, PLEASE HELP ME OUT!!!
Code:
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace std;
const int max=20;
void getthem ( int [], int&, ifstream ) ;
void printthem ( const int [], int, int, ofstream) ;
float curvegrade(int , int);
float getmax ( const int[], int, int&);
int main ()
{
ifstream infile;
ofstream outfile;
int numgrades;
int grades[max];
int maxg;
//***********************************Open files and check for errors**********************************
infile.open ("indata7.txt");
if (!infile)
{
cout << " CAN’T OPEN INPUT FILE ! " << endl;
return 1;
}
outfile.open ("outdata7.txt");
if (!outfile)
{
cout << " CAN’T OPEN INPUT FILE ! " << endl;
return 1;
}
//***********************************Call functions**************************************************
getthem(grades, numgrades, infile);
getmax(grades, numgrades, maxg);
printthem(grades, maxg, numgrades, outfile) ;
return 0;
}
void getthem (int grades[], int& num, ifstream infile)
{
int m;
num = 0;
m=0;
while (infile)
{
infile >> grades[m];
num = num + 1 ;
m++;
}
}
float getmax (const int grades[], int number, int& maxgrade)
{
int m;
maxgrade = grades[0];
for (m = 1; m < number; m++)
{
if (grades[m] > maxgrade)
maxgrade = grades[m];
}
return maxgrade;
}
void printthem (const int grades[], int maxgd, int number, ofstream outfile)
{
int m;
outfile<<"Student Absolute Curved"<<endl<<"Number Grade Grade"<<endl<<"--------- ----------- -----------"<<endl;
for (m =1; m < number; m++)
{
outfile<<m<<setw(20)<<grades[m-1]<<setw(14)<<curvegrade(grades[m-1], maxgd)<<endl;
}
}
float curvegrade(int absgrade, int maxgrade)
{
int curve;
static_cast<int>(static_cast<float>(curve = (absgrade/maxgrade * 100) + .5) ) ;
return curve;
}
Input file is indata7.txt
60
75
69
85
92
88
84
73
93
54
Thanks, and please help asap!!!
and i'm using Visual C++ 6.0