Question

what am i doing wrong here ? starting out with c++ early objects 9th edition chapter...

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;
}

Homework Answers

Answer #1
#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
read a text file into two parrall arrays. The file has a name and a grade...
read a text file into two parrall arrays. The file has a name and a grade here is what I am doing not working #include < iostream> #include < fstream> #include <string> usind namespace std; int main() { int const size =2; string names[size]; int age[size]; ifstream inputFile; inputFile.open("text.txt"); for (int i = 0; i <size; i++) { inputFile >> names[i]; inputFile>> age[i]; cout << age[i] << endl; cout << name[i] << endl; } inputFile.close(); return 0; }
Lab 6    -   Program #2   -   Write one number to a text file. Use the write()...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write() and read() functions with binary                                                        data, where the data is not char type.              (Typecasting is required) Fill in the blanks, then enter the code and run the program. Note:   The data is int type, so typecasting is            required in the write() and read() functions. #include <iostream> #include <fstream> using namespace std; int main() {    const int SIZE = 10;   ...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include <cmath> using namespace std; int getWeight(); float deliveryCharge(int weight); void displayCharge(int weight); int main () {    displayCharge(getWeight());    return 0; }   int getWeight() {    int weight;    cout << "Enter package weight (oz): ";    cin >> weight;    return weight; } float deliveryCharge(int weight) {    if (weight > 16)    {        return (((weight - 16) / 4) *...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
Convert this C++ to JavaScript and run in browser. #include <cstdlib> #include <ctime> #include <sstream> #include...
Convert this C++ to JavaScript and run in browser. #include <cstdlib> #include <ctime> #include <sstream> #include <iostream> using namespace std; /* * */ class Dice{ private: static const int MAXDICE=6; static const int MINDICE=1; int faceVal; public: Dice(int); void setFace(int); int getFace(); string toString(); }; Dice::Dice(int faceVal) { if(faceVal<MINDICE&&faceVal>MAXDICE) { setFace(1); } else { this->faceVal=faceVal; } } void Dice::setFace(int faceVal) { this->faceVal=faceVal; } int Dice::getFace() { return faceVal; } string Dice::toString() { stringstream ss; ss<<faceVal; string str="face value is ";...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
C++ PROGRAM When I input 3 S P R, it was suppoesed to pop up L...
C++ PROGRAM When I input 3 S P R, it was suppoesed to pop up L W T. But it showed L L L.IDK why the moveNo is not working. I am asking for help, plz dont put some random things on it. main.cpp #include <iostream> #include "computer.h" #include "human.h" #include "referee.h" using namespace std; int main() {     human h;     computer c;     referee r;     r.compare(h,c);     return 0; } computer.cpp #include<iostream> #include "computer.h" using namespace std;...
For some reason I followed the steps in my project and I am getting the incorrect...
For some reason I followed the steps in my project and I am getting the incorrect output and when I am submitting it, it gives me compilation error. Printing empty array -- next line should be blank Testing append: Shouldn't crash! Should print 100 through 110 below, with 110 on a new line: 100 101 102 103 104 105 106 107 108 109 110 Checking capacity of new array: OK Append test #2: Should print 100 through 120 below, on...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is up to you as long as you implement some form of inheritance. Below is my code however the credit and the actual menu isn't working. Can i get some help on getting the menu to work properly. // BankAccount.h #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> #include <iostream> using namespace std; class BankAccount { protected : int noOfWithdrawls; private: // Declaring variables    float balance;...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT