Basics of Streams, finding the highest number in a set.

I am trying to create a program that looks at a file in a folder. The file has names and grades on it, and I want the program to tell me which student has the highest grade, and cout it.
Here is my code so far:
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
#include <stdlib.h>
#include <iostream.h>	// standard input output functions
#include <iomanip.h>	// format output
#include <fstream.h>    // must be included to access files
#include <math.h>	// Built-in Math functions
#include "utilities.h"
#include "apstring.h"
#include "apvector.h"
using namespace std;


int main()
{
    do{
        apstring filename;
        cout<<"Please enter the data file name: ";
        cin>>filename;
// this part is just setting up the streams, opening the file.
        ifstream fin;
        fin.open(filename.c_str());

        if (fin.fail())//for if there is a problem opening the file
        {
            cout<<"Error opening"<<filename<<endl;
        }
        string first; //first name of the student
        double grade;//the grade they earned
        double max;//i was thinking that i could use this for the highest grade
        fin>>first>>grade; //general testing to get SOMETHING to show up
        cout<<first<<"     "<<grade<<endl;

        

        fin.close();
    } while (!Exit("[A] Another Program, [E] Exit",'A','E'));
    return (EXIT_SUCCESS);
}//End Main




i was thinking that i need to set up some sort of while loop, but looping was never my strong point, and i'm not quite sure how to go about it.
Any help or advice would be appreciated. Thanks!
1
2
3
4
5
6
7
fin >> max_name >> max_grade;
while( fin >> name >> grade){
   if(grade > max_grade){
      max_grade = grade;
      max_name = name;
   }
}

think about it..
Topic archived. No new replies allowed.