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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
// Function Declarations
void sortIncreasingOrder(double& a, double& b, double& c, double& d, double& e);
void getNumbersFromUser(double & a, double& b, double & c, double& d, double& e);
double sum(double a, double b, double c, double d, double e);
double average(double sum, int number);
double median(double a, double b, double c, double d, double e);
double findSmallestNumber(double a, double b, double c, double d, double e);
double findLargestNumber(double a, double b, double c, double d, double e);
void sortIncreasingOrder(double& a, double& b, double& c, double& d, double& e);
void sortDecreasingOrder(double& a, double& b, double& c, double& d, double& e);
int main()
{
double a,b,c,d,e;
int choice; // No need to set this yet.
// if (choice < 9) // Useless if. Do while will happen one no matter what.
do
{
/* cout << */ "-----------------------------------------------\n"
/* cout << */ "Welcome to the Jayhawk Statistical Institute\n"
// cout << "Please enter a choice: " << endl;
/* cout << */ "Make a selection:\n"//;
/* cout << */ "1 - Enter numbers\n"//;
/* cout << */ "2 - Calculate sum\n"//;
/* cout << */ "3 - Calculate average\n"//;
/* cout << */ "4 - Calculate median\n"//;
/* cout << */ "5 - Find the smallest number\n"//;
/* cout << */ "6 - Find the Largest number\n"//;
/* cout << */ "7 - Sort numbers in increasing order\n"//;
/* cout << */ "8 - Sort numbers in decreasing order\n" //;
/* cout << */ "9 - Exit \n" //;
/* cout << */ "Enter Choice.\n >";
cin >> choice;
switch (choice)
{
case 1: getNumbersFromUser (a,b,c,d,e); break;
case 2: cout << "The sum of these numbers is: " << sum(a,b,c,d,e) << endl;
break;
case 3:
// double avg;
// double average( double sum, int number);
// cout << "the average of those numbers is: " << avg << endl;
// Make this a single line?
cout << "The average of the 5 numbers is: " << avg(sum(a,b,c,d,e), 5) << endl;
break;
default:
cout << "Invalid Choice" << endl;
}
// Bad spot for return. Its in the loop. Put it outside.
//return 0;
} while(choice != 9);
return 0;
}
// Function Definitions
void getNumbersFromUser(double& a, double& b, double& c, double& d, double& e)
{
/*
double num1,num2,num3,num4,num5;
cout << "Enter 5 Numbers" << endl;
cin >> num1;
cin >> num2;
cin >> num3;
cin >> num4;
cin >> num5;
cout << num1<< num2 << num3 << num4 << num5 << endl;
*/
// Incorrect way of getting vars. Try this:
cout << "Enter 5 Numbers.\n";
cin >> a >> b >> c >> d >> e;
}
double sum(double a, double b, double c, double d, double e)
{
/* double num1;
double num2;
double num3;
double num4;
double num5;
double sum = num1 + num2 + num3 + num4 + num5;
return sum; */
// You don't need to make a variable. Just do the operation in the return.
return a+b+c+d+e;
}
double average(double sum, int number)
{
/* double avg;
double num = 5;
avg = sum/num;
return avg; */
// Do operation in return.
return sum/number;
}
void sortIncreasingOrder(double& a, double& b, double& c, double& d, double& e)
{
vector<double> n;
n.push_back(a);
n.push_back(b);
n.push_back(c);
n.push_back(d);
n.push_back(e);
sort(n.begin(),n.end());
a = n[0]; b = n[1]; c = n[2]; d = n[3]; e = n[4];
}
|