I am a beginner in c++ coding and i have an assignment for my class. I am trying to read the first line of integers separated by spaces 2 spaces in the file (cannot use arrays or vectors). I have seen many tutorials telling me to use getline () and simply reading each and every integer and storing it into its own variable, but neither method has been working for me. Does anybody have a way to read in the first line with a while loop and have it so that I can then find the maximum and minimum values from the line, as well as calculate the average EXCLUDING the maximum and minimum values?
sample input i was instructed to analyze is as follows
5 7 9 8 7
30032
51111
52000
42000
9 8 6 3 7
70000
23765
24000
41004
Here is what I have so far.
{
void PrintIntro (); {
cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" <<endl;
cout << "Welcome to Tallahassee Idol! Where Stars are Born!!!" <<endl;
cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" <<endl<<endl;
}
/*******************************************************************************/
void OpenFile (); {
ifstream myFile; // filestream for input file
string fileName; // string for user to input filename
cout <<"Enter a valid filename (no blanks please): ";
cin >> fileName;
myFile.open(fileName);
while (!myFile) {
cout << "Please re-enter a valid filename: "<<endl<<endl;
cin >> fileName;
myFile.open(fileName);
}
}
/*******************************************************************************/
void GetJudgeScore1 (); {
ifstream myFile; // filestream for input file
string fileName; // string for user to input filename
int player1Total = 0; // total score for player 1
int player1Average = 0; // average for player 1
int highScore1 = 0; // highest score to be excluded
int lowScore1 = 100; // lowest score to be excluded
const int judgeAmt = 5;
cout << "Processing Judge Data for Contestant 1" <<endl;
cout << "=====================================" <<endl;
cout << "Judge scores are: ";
if (myFile.is_open()){ // if the file is open, read data in
// here is where i ran into problems
}
}
return 0;
}