Thread: Need help with finding median in an array

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    12

    Need help with finding median in an array

    nevermind
    Last edited by gevans; 04-16-2013 at 03:16 PM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    So do you have a question?

    Perhaps you could be so kind as to post the complete error messages, exactly as they appear in your development environment.


    Jim

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    12
    yes,its not running.what am i doing wrong for getting the median and outputting it. theres 22 errors
    Last edited by gevans; 04-16-2013 at 03:03 PM.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    You may want to start by fixing the errors your compiler is telling you about.

    Just a small list to start, many, many more following these.
    ||=== c++homework, Debug ===|
    main.cpp||In function ‘int main()’:|
    main.cpp|15|error: invalid conversion from ‘int (*)()’ to ‘int’ [-fpermissive]|
    main.cpp|16|error: ‘array1’ was not declared in this scope|
    main.cpp|17|error: expected primary-expression before ‘]’ token|
    main.cpp|17|error: ‘elems’ was not declared in this scope|
    main.cpp|18|error: ‘median1’ was not declared in this scope|
    main.cpp||In function ‘int numScores()’:|
    main.cpp|29|error: no match for ‘operator>>’ in ‘std::cin >> numScores’|

    Code:
    #include <iostream>
    
    using namespace std;
    
    int numScores();
    float array(int numscores);
    void getScores(int numscores,float array1);
    void sortArray1(float array1[], int elems);
    int binarySearch(float array1, int numScores, float median1);
    void outputArray(float array1,int numScores,float median1);
    
    int main()
    {
        numScores();
        array(numScores);
        getScores(numScores,array1);
        sortArray1(array1[],elems);
        binarySearch(array1, numScores,median1);
        outputArray(array1,numScores,median1);
        system("pause");
        return 0;
    }
    
    int numScores()
    {
        do
        {
        cout << "Please enter how many scores you have to enter: " << endl;
        cin >> numScores;
    
        }
        while (numScores > 25 || numScores < 5);
    
     return numScores;
    }
    
    float array(int numScores)
    {
          float array1[numScores];
          array1=new float*;
         if (array1==0)
         {
          exit(2);
         }
    return array1;
    }
    
    void getScores(int numScores,float array1)
    
    {
         for (int i=0;i<numScores;i++)
        {
             do {
             cout << " Please enter your 1st score now: " << endl;
             cin >> array[i];
              } while (array[i] > 100 && array[i] < 0)
    
         }
    }
    void sortArray1(float array1[], int elems)
    {
        bool swap;
        float temp;
        do
        {
            swap = false;
            for (int count = 0; count < (elems - 1); count++)
            {
                if (array[count] > array[count + 1])
                {
                    temp = array[count];
                    array1[count] = array1[count + 1];
                    array1[count + 1] = temp;
                    swap = true;
                }
            }
        } while (swap);
    }
    
    
     int binarySearch(array1, int numScores, int median1)
    {
        int first = 0, // First array element
        last = numScores - 1, // Last array element
        middle, // Mid point of search
        position = -1; // Position of search value
        bool found = false; // Flag
        while (!found && first <= last)
        {
            middle = (first + last) / 2; // Calculate mid point
            if (array1[middle] == value) // If value is found at mid
            {
      found = true;
                position = middle;
            }
    
        }
        return position;
    }
    
    
    }
    void outputArray(float array1,int numScores,float median1)
    {
         for(int i=0; i< numScores; i++)
            {
             cout << array[i] << endl;
             cout << middle << endl
            }
    }
    Jim
    Last edited by jimblumberg; 04-16-2013 at 03:37 PM. Reason: Added deleted code.

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    12
    Quote Originally Posted by jimblumberg View Post
    You may want to start by fixing the errors your compiler is telling you about.

    Just a small list to start, many, many more following these.


    Jim

    how do i fix it? i dont know what its saying/how to.

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by gevans View Post
    how do i fix it? i dont know what its saying/how to.
    Nobody can help you if you delete your code...

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Continued here -> need help with errors
    Please keep to one thread per subject.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Median and Mode of an Array
    By skmightymouse in forum C Programming
    Replies: 3
    Last Post: 04-29-2012, 12:36 PM
  2. Median in array
    By PvtVampire in forum C Programming
    Replies: 4
    Last Post: 10-14-2011, 10:22 AM
  3. Replies: 5
    Last Post: 04-07-2011, 10:40 PM
  4. Finding Mode Median and Mean
    By Ginny Morgan in forum C Programming
    Replies: 3
    Last Post: 05-08-2003, 03:09 PM
  5. Help with finding median with arrays.
    By Niloc1 in forum C Programming
    Replies: 3
    Last Post: 03-26-2002, 03:32 PM