I need to create a program that reads the file, and displayed 3 lanes which have the top 3 greatest numbers, from largest to smallest. ive try so many ways to figure it out, but failed. plz help me with this quetion. here is the file list and the code ive try.
BADBOY1 3.50 APRIL/2/2016
BADBOY2 5.00 APRIL/2/2016
BADBOY3 0.50 APRIL/2/2016
BADBOY4 3.80 APRIL/2/2016
BADBOY5 1.50 APRIL/2/2016
BADBOY6 15.50 APRIL/2/2016
BADBOY7 39.50 APRIL/2/2016
BADBOY8 6.50 APRIL/2/2016
BADBOY9 51.50 APRIL/2/2016
BADBOY10 32.50 APRIL/2/2016
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
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
string name, points, date;
ifstream inFile;
string items;
inFile.open("badboys.txt");
if(!inFile){
cerr<<"Error! inFile cannot open. "<<endl;
}
while(inFile>>name>>points>>date){
if(top1<score){top1=score;}
if (!inFile){break;}
}
cout<<top1<<endl;
inFile.close();
}
|