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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream.h> // library for input/output
#include <conio.h> // console input/output
void FindGreatest(int, int, int, int&);
void FindMiddle(int, int, int, int&);
void FindLeast(int, int, int, int&);
int main()
{
clrscr();
int number_one;
int number_two;
int number_three;
int largest;
int middle;
int least;
cout << "Enter the first number: " << endl;
cin >> number_one;
cout << "Enter the second number: " << endl;
cin >> number_two;
cout << "Enter the third number: " << endl;
cin >> number_three;
FindGreatest(number_one, number_two, number_three, largest);
FindMiddle(number_one, number_two, number_three, middle);
FindLeast(number_one, number_two, number_three, least);
cout << "\n" << largest << " " << middle << " " << least << endl;
getch();
return 0;
}
void FindGreatest(int number_one, int number_two, int number_three, int &largest)
{
if( number_one > number_two && number_one > number_three)
largest = number_one;
else if( number_two > number_one && number_two > number_three)
largest = number_two;
else
largest = number_three;
}
void FindMiddle(int number_one, int number_two, int number_three, int &middle)
{ //doing what you wanted to do in short
int l_least;
int l_largest;
FindGreatest(number_one, number_two, number_three, l_largest);
FindLeast(number_one, number_two, number_three, l_least);
middle = ( number_one + number_two + number_three) - (l_largest + l_least);
}
void FindLeast(int number_one, int number_two, int number_three, int &least)
{
if( number_one < number_two && number_one < number_three)
least = number_one;
else if( number_two < number_one && number_two < number_three)
least = number_two;
else
least = number_three;
}
|