aboutsummaryrefslogtreecommitdiff
path: root/num1.cpp
diff options
context:
space:
mode:
authorTyler Taormina <[email protected]>2021-11-23 16:07:20 -0800
committerTyler Taormina <[email protected]>2021-11-23 16:07:20 -0800
commitafc2a286cd75bd14ae5e540ce1dc8a00c77fe025 (patch)
tree4b5b36911f22d3d42330fab97cc0f9707e512fb3 /num1.cpp
parentAdding new files. (diff)
downloadcst115-lab8-till-t-afc2a286cd75bd14ae5e540ce1dc8a00c77fe025.tar.xz
cst115-lab8-till-t-afc2a286cd75bd14ae5e540ce1dc8a00c77fe025.zip
11.9 complete
Diffstat (limited to 'num1.cpp')
-rw-r--r--num1.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/num1.cpp b/num1.cpp
index e69de29..48c19aa 100644
--- a/num1.cpp
+++ b/num1.cpp
@@ -0,0 +1,66 @@
+// Tyler Taormina
+// CST 116
+// Nov 2021
+// Lab 8 Exercises
+
+
+#include <iostream>
+using namespace std;
+
+void findMedian(float arr[], int);
+float GetValues (float values[]);
+#define MAX 20
+
+int main ()
+{
+ int num_values;
+ float values [MAX] = {0};
+ num_values = GetValues(values);
+
+ cout << "Here is our list..." << endl;
+ for (int i = 0; i < num_values; i++)
+ cout << values[i] << " ";
+ cout << endl;
+
+ cout << "===================================================" << endl;
+
+ findMedian(values, num_values);
+ return 0;
+}
+
+
+float GetValues (float values[])
+{
+ int num_values = 0;
+ char cont = 'n';
+
+ do
+ {
+ cout << "Enter a number: ";
+ cin >> values[num_values++];
+
+ cout << "Enter another values (y/n)? ";
+ cin >> cont;
+ } while (toupper (cont) == 'Y' &&
+ num_values < MAX);
+ return num_values;
+}
+
+void findMedian(float arr[], int num_val)
+{
+ float x;
+
+ if ((num_val % 2) == 0)
+ {
+ x = (arr[num_val/2] + arr[(num_val/2) - 1])/2;
+
+ cout << "Even number Array. We will average the two middle most numbers to determine the median." << endl;
+ cout << "The median is: " << x << endl;
+ }
+ else
+ {
+ cout << "Odd number Array. We will find the number in the middle of the list which determines the median." << endl;
+ cout << "The median is: " << arr[num_val/2] << endl;
+ }
+
+}