I'm doing a program that uses an input file with 587 lines. Each line has four numbers. For each line we're supposed to find the largest, second largest, and smallest numbers and we're supposed to use a seperate function for this. I tried using if statements but ended up confusing myself. Is there any better way to this.
CODE
#include <iostream>
#include <fstream>
int Find(float,float,float,float&,float&,float&);
using namespace std;
int main();
{
int x1;
int x2;
int x3;
int x4;
ifstream Find;
ofstream Output;
Find.open("f:/prj5in.txt");
Output.open("f:/prj5out.txt")
Find<<x1<<x2<<x3<<x4<<endl;
cout<<Find(x1,x2,x3,x4,greatest,second_greatest,smallest);
cin.get();cin.get();
return 0;
}
int Find(float x1,float x2,float x3,float x4 float& greatest, float& second_greatest,float& smallest)
{
int count=1;
float t, u;
while(Find)
{
if (x1>x2)
{
t = x1;
u = x2;
}
else
{
t = x2;
u = x1;
}
if (x3>t && x3>u)
{
greatest = x3;
if (x3>t || x3>u)
{
second_greatest=x3
}
else
greatest = t;
if (x1<x2)
u = x1;
else
u = x2;
if (x3<u)
smallest = x3;
else
smallest = t;