#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main ()
{
ifstream fin("program4.txt");
ofstream fout("output4.txt");
string lastName;
string firstName;
string fournumbers;
if(fin.fail())
{
cerr << "Unable to open input file\n";
exit(2);
}
if(fout.fail())
{
cerr << "Unable to open output file\n";
exit(3);
}
while (fin >> firstName >> lastName >> fournumbers)
{
fout << setw(10) << firstName << setw(10) << endl;
fout << setw(10) << lastName << setw(10) << endl;
fout << setw(10) << fournumbers << setw(10) << endl;
}
cout << "Now go check the output4.txt file\n" << endl;
fin.close();
fout.close();
return 0;
}
Hey guys, I'm supposed to write a program that will take the largest of four numbers of an input file (such as 816 423 12 15) and display the TWO largest numbers next to the name the original four were sitting by. Example (this isn't code, its the input file):
JAMES SMITH 828 786 584 24
Then after the program uses them, it displays the following in an output file:
JAMES SMITH 828 24
So far, I've gotten the output file to show everything in a single colum, and it does not sort the two largest numbers. Why is that?