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:
#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"
usingnamespace 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!