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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#include <iostream>
#include <fstream> //needed to input files
#include <string> //needed for string input
using namespace std;
//Function prototype.
void getScore(ifstream& myfile, int grade1, int grade2, int grade3, int grade4, int grade5, string grades);
int findLowest(int grade1, int grade2, int grade3, int grade4, int grade5);
void calcAverage(int grade1, int grade2, int grade3, int grade4, int grade5);
void open(ifstream&);
void didnotopen(ifstream&);
int main()
{
ifstream myfile;
int grade1 = 0, grade2 = 0, grade3 = 0, grade4 = 0, grade5 = 0;
//open file
open(myfile);
//get score
getScore(myfile, grade1, grade2, grade3, grade4, grade5); //This where I am having an issue. What should I put in ()?
}
//****************************************************************************
//open file
//****************************************************************************
void open(ifstream& myfile)
{
myfile.open("grades.txt");
didnotopen(myfile);
}
//****************************************************************************
//did the file open
//****************************************************************************
void didnotopen(ifstream& myfile)
{
if (!myfile)
{
cerr << "\n Error: Unable to read file." << endl;
exit(10);
}
}
//****************************************************************************
//GetScore function
//****************************************************************************
void getScore(ifstream& myfile, int grade1, int grade2, int grade3, int grade4, int grade5, string grades)
{
{
while (myfile >> grades)
myfile >> grade1;
myfile >> grade2;
myfile >> grade3;
myfile >> grade4;
myfile >> grade5;
cout << grade1 << endl;
cout << grade2 << endl;
cout << grade3 << endl;
cout << grade4 << endl;
cout << grade5 << endl;
}
}
//*********************************************
//Find lowest function
//*********************************************
int findLowest(int grade1, int grade2, int grade3, int grade4, int grade5)
{
int lowest = grade1;
if (grade2 < lowest)
{
lowest = grade2;
}
else if (grade3 < lowest)
{
lowest = grade3;
}
else if (grade4 < lowest)
{
lowest = grade4;
}
else if (grade5 < lowest)
{
lowest = grade5;
}
return lowest;
}
//*********************************************
//CalcAverage
//*********************************************
void calcAverage(int grade1, int grade2, int grade3, int grade4, int grade5)
{
double gpa;
int lowest = findLowest(grade1, grade2, grade3, grade4, grade5);
gpa = ((grade1 + grade2 + grade3 + grade4 + grade5) - lowest) / 4.0;
cout << "The grade point average is " << gpa << endl;
}
|