My teacher gave us an assignment where she wanted us to write a program that would read test score data from a text file,drop the lowest test score,average the other three test scores, and output the data to a text file. I've spent three days trying to figure out how to drop the lowest test score. My teacher won't let us use void statements or arrays. The test data is just numbers with no characters involved, but i'm really tired so if anybody can please take a look at my code and tell me what's wrong so I can fix it and go to sleep that would be so coool.
# include <iostream>
# include <fstream>
# include <string>
# include <iomanip>
using namespace std;
double FindFirst(double,double,double,double,double);
int main()
{
ifstream inFile;
ofstream outFile;
double test1;
double test2;
double test3;
double test4;
double first;
inFile.open("H:\\tests.txt");
outFile.open("H:\\outData_2.txt");
inFile >> test1>>test2>>test3>>test4;
while (!inFile.eof())
{
outFile<< fixed<< showpoint<<endl;
outFile<<setprecision(1)<<endl;
outFile<<setw(6)<<"Test 1"<<setw(6)<<"Test2 "<<setw(6)<<"Test3"<<setw(6)<<"Test4 "<<setw(6)<<"Average"<<endl;
if(!inFile.eof())
{
first=0;
first = FindFirst(test1,test2,test3,test4,first);
}
outFile<<setw(6)<<test1<<setw(6)<<test2<<setw(6)<<test3<<setw(6)<<test4<<setw(6)<<first<<endl;
inFile>>test1>>test2>>test3>>test4;
if (inFile.eof())
outFile<<"This program was created by Gainor Whitaker.End of program."<<endl;
}
inFile.close();
outFile.close();
return 0;
}
double FindFirst(double test1,double test2,double test3,double test4,double first)
{
if(test1>test2&&test3>test4)
first = test1;
else if(test4>test1&&test2>test3)
first = test4;
else if(test3>test4&&test1>test2)
first = test3;
else if(test2>test3&&test4>test1)
first = test2;
return first;
}
the following is the input data:
75 85 95 65
89 90 79 87
70 68 77 82
50 92 86 88
87.5 91.5 66.5 78.5
I am at my wits end here. I can get the program to store the data and average the scores, but finding the lowest one and dropping it is killing me. If you can help me you are the greatest person ever.