Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to write a program to search a file of numbers of type intand write the l

ID: 3618999 • Letter: I

Question

I need to write a program to search a file of numbers of type intand write the largest and smallest to the screen.

this is the code i have so far but am confused on my "while"loop.
please help asap its due tom!
thanks.
______________________________________________________
#include <iostream> // for streams
#include <fstream> // for files
#include <cstdlib>   // for exit

using namespace std;

int main()
{
    char fileName [13];
    int input, largest, smallest;

cout << "Enter a file name. This Program limitsfile names to"
         << endl<< " a maximum of 12 characters. " << endl;
    cin >> fileName; //get the name of theexternal file

ifstream infile; //declare internal (toprogram) name of the input file
    infile.open(fileName);

    //Check to see if we were able to open the file,if not get out
    if(!infile)
{
         cout <<"Cannot open file " << fileName
               << " Aborting program " << endl;
         exit (1);
}

    //read in the first line of the file
infile >> input;

    //initialize largest and smallest
largest = input;
    smallest = input;

    while( ! infile.eof()) //process each line untilend-of-file is reached
    {
        *** Your code here***

         infile >>input; //get the next line
    }

cout << "smallest in file = " <<smallest
           << " largest in file = " << largest << endl;

    infile.close();
return 0;
}

Explanation / Answer

x.P5e is the answer for the question you asked for it reads in a set of numbers of int, and outputs the smallest and largest numbers to the screen. To help you to get the smallest and largest is when you first get your first integer set that integer equal to the smallest and largest. That way each number is compared to that number. And if their is a number that is larger or smaller set that integer to the smallest or largest. It also contains a function for the introduction of the program what it is about to do. Below is the source code :