I cannot find out what is wrong with my meanFunction. It keeps returning a weird set of numbers. PLEASE HELP!
Code Posted:
#include <iostream>
#include <cmath>
using namespace std;
float meanFunction(float *arr, int count);
float medianTotal(float *arr, int count);
int main() {
int count = 0, go_on = 0;
float num[100], mean, median, *arr = num;
tryAgain: // Statement Label
cout << "This program will calculate the mean, median, mode, and standard deviation. " << endl;
cout << "Enter the amount of values that you will select (must be 100 or less), the program will self terminate once hitting that value." << endl;
cin >> go_on;
if (go_on > 100) {
cout << "Please follow the directions!" << endl;;
goto tryAgain;
}
cout << "You have entered " << go_on << " values." << endl;
do {
cout << "Enter a number: ";
cin >> num[count];
count++;
median = medianTotal(arr, count);
}
while (count < go_on);
mean = meanFunction(arr,count);
cout << "The Mean is: " << mean << endl;
cout << "The Median is: " << median << endl;
return 0;
}
float meanFunction(float *arr, int count) {
float sum = 0;
for (int i = 0; i <= count; i++) {
sum += arr[i];
}
return (sum / count);
}
float medianTotal(float *arr, int count){
int middle = (count / 2);
float average;
if ((count % 2) == 0){
average = ((arr[middle - 1] + arr[middle]) / 2);
}
else {
average = (arr[middle]);
}
return average;
}
#include <iostream>
#include <cmath>
usingnamespace std;
float meanFunction(float *arr, int count);
float medianTotal(float *arr, int count);
int main() {
int count = 0, go_on = 0;
float num[100], mean, median, *arr = num;
tryAgain: // Statement Label
cout << "This program will calculate the mean, median, mode, and standard deviation. " << endl;
cout << "Enter the amount of values that you will select (must be 100 or less), the program will self terminate once hitting that value." << endl;
cin >> go_on;
if (go_on > 100) {
cout << "Please follow the directions!" << endl;;
goto tryAgain;
}
cout << "You have entered " << go_on << " values." << endl;
do {
cout << "Enter a number: ";
cin >> num[count];
count++;
median = medianTotal(arr, count);
}
while (count < go_on);
mean = meanFunction(arr,count);
cout << "The Mean is: " << mean << endl;
cout << "The Median is: " << median << endl;
return 0;
}
float meanFunction(float *arr, int count) {
float sum = 0;
for (int i = 0; i <= count; i++) {
sum += arr[i];
}
return (sum / count);
}
float medianTotal(float *arr, int count){
int middle = (count / 2);
float average;
if ((count % 2) == 0){
average = ((arr[middle - 1] + arr[middle]) / 2);
}
else {
average = (arr[middle]);
}
return average;
}