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
|
#include <iostream>
using namespace std;
int main()
{
//declare the variables
double number1,
number2,
number3,
number4,
number5,
median;
//Explain the program and prompt for input
cout << "Please input three numbers and this program will find the ";
cout << "mean of those numbers.\n\n";
cout << "First Number: ";
cin >> number1;
cout << "Second Number: ";
cin >> number2;
cout << "Third Number: ";
cin >> number3;
cout << "Fourth Number: ";
cin >> number4;
cout << "Fifth Number: ";
cin >> number5;
if (number1 > number2) //Swap first slot if necessary
swap(number1, number2);
if (number1 > number3)
swap(number1, number3);
if (number1 > number4)
swap(number1, number4);
if (number1 > number5)
swap(number1, number5);
//Swap second slot if necessary
if (number2 > number3)
swap(number2, number3);
if (number2 > number4)
swap(number4, number4);
if (number2 > number5)
swap(number2, number5);
//Swap third slot if necessary
if (number3 > number4)
swap(number3, number4);
if (number3 > number5)
swap(number3, number5);
//Swap fourth slot if necessary
if (number4 > number5)
swap(number4, number5);
cout << "\nThe median of " << number1 << ", " << number2 << ", and " << number3 << ", " << number4 << ", and " << number5 << " is... " << number3;
system("pause");
return (0);
}
|