Min/Max/counter/while loop from file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
    The program is supposed to read in text from a given file ( different samples provided in the homework but not relevant here), set the first number in the file as min and max number, then use a while loop to change the min and max number according to which number comes next in the file. Example: if the first number is 1, the min and max is now 1. The next number is 3, the min stays at 1 and the max is now 3 and this continues until end of file. The program is also supposed to count how many integers are in the file.

  2. Relevant commands, code, scripts, algorithms:

  3. The attempts at a solution (include all code and scripts):

#include<cstdlib>
#include<iostream>
#include<fstream>
#include<string>
using namespace std;


int main()
{
  ifstream fin;                    // declare an input file stream
  string file_name;
  double x,min,max,count;
  
 

  cout << "Enter input  file name:";
  cin>>file_name;
  
  fin.open(file_name.c_str(),ios::in);       // open file file_name for input
  
  if (!fin.is_open())                      // check if file is open for input
    {
      cerr << "Unable to open input file stream  " << file_name << endl;
      exit(10);
    }
     
  fin>>x; // read txt from file
  x=min; // setting first number imput as min
  x=max; // setting first number imput as max
   
 
  count = 0; // initialize counter
  
  while(fin)
    {
      fin>>x;
      if(x<min)
    x=min;
      if(x>max)
    x=max;
      count++;
      fin>>x;
    }
  cout<<"total number"<<count<<endl;
  cout<<"Minimum: "<<min<<endl;
  cout<<"Maximum: "<<max<<endl;

  fin.close();        // close file stream fin
  return 0;  
}
  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    The Ohio State University, Columbus Ohio, USA, Yi Wang, cse1222

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

And?

What is your issue...