Purpose: The purpose of this program is the following:
Read in the input file and organize the data inside from lowest to highest.
Send the new data into an output text file.
Close everything and reopen the output text file onto the screen.
How can I accomplish the above with the Dev C++ compiler? The code below is error-free, as far as I can tell.
#include <iostream>
#include <fstream>
usingnamespace std;
int main()
{ int a, b, c;
ifstream fin("input.txt");
ofstream fout("output.txt");
fin >> a >> b >> c;
cout << a << b << c <<endl;
while (a != -1)
{
if(a<b && b<c)
fout<<a<<" "<<b<<" "<<c<<endl;
elseif(b<c && c<a)
fout<<b<<" "<<c<<" "<<a<<endl;
elseif(c<a && a<b)
fout<<c<<" "<<a<<" "<<b<<endl;
elseif(b<a && a<c)
fout<<b<<" "<<a<<" "<<c<<endl;
elseif(c<b && b<a)
fout<<c<<" "<<b<<" "<<a<<endl;
elseif(a<c && c<b)
fout<<a<<" "<<c<<" "<<b<<endl;
fin >> a >> b >> c;
}
fin.close();
fout.close();
fin.open("output.txt");
fin >> a >> b >> c;
while (!fin.eof())
{
cout << a << b << c <<endl;
fin >> a >> b >> c;
}
fin.close();
return 0;
}