what am i doing wrong here ? starting out with c++ early objects 9th edition chapter 10 programming challenge 6
#include <iostream>
using namespace std;
int main() {
double findMedian(int* numbers, int size) {
double median;
if (size % 2 == 0)
median = (double)(*(numbers +
((size - 1) / 2))
+ *(numbers +
(((size - 1))) / 2;
else
median = *(numbers + ((size - 1) / 2));
return median;
}
double findMedian(int*, int);
const int SIZE = 5;
int numbers[SIZE] = { 2, 4, 5, 7, 8 };
std::cout << "Median of array is:" <<
median;
return 0;
}
double findMedian(int* numbers, int size) {
double median;
if (size % 2 == 0);
median = (double)(*(numbers + ((size - 1) / 2)) +
*(numbers + (((size - 1) / 2) + 1))) / 2;
else
median = *(numbers + ((size - 1) /
2));
return median;
}
#include <iostream> using namespace std; double findMedian(int *, int); int main() { const int SIZE = 5; int numbers[SIZE] = {2, 4, 5, 7, 8}; std::cout << "Median of array is:" << findMedian(numbers, SIZE) << endl; return 0; } double findMedian(int *numbers, int size) { double median; if (size % 2 == 0) median = (double) (*(numbers + ((size - 1) / 2)) + *(numbers + (((size - 1) / 2) + 1))) / 2; else median = *(numbers + ((size - 1) / 2)); return median; }
Get Answers For Free
Most questions answered within 1 hours.