Thread: need help with errors

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

    need help with errors

    Code:
    #include <iostream>
    #include <iomanip>
    #include <cstdlib>
    using namespace std;
    
    
    int numScores();
    float* array(int numscores);
    void getScores(int numscores,float* array1);
    void sortArray1(float array1[], int elems);
    float median( float array1,int numScores);
    void output1(float array1, float median, int numScores);
    
    
    int main()
    {
        int numScores1;
        float* array1;
        int median;
        numScores1= numScores();
        array1=array(numScores1);
        getScores(numScores,array1);
        sortArray1(array1[],elems);
        binarySearch(array1, numScores,median1);
        outputArray(array1,numScores,median1);
        median(array1,numScores1);
        output1(array1, median1,numScores);
        system("pause");
        return 0;
    }
    
    
    int numScores()
    { 
        int numScores1;
    
    
        do
        {
        cout << "Please enter how many scores you have to enter: " << endl;
        cin >> numScores1;
        
        }
        while (numScores1 > 25 || numScores1 < 5);
    
    
     return numScores1;
    }
    
    
    float* array(int numScores)
    {
           int numScores1;
          float* array1;
          array1=new float[numScores1];
         if (array1==0) 
         { 
          exit(2);
         }
    return array1;
    }
    
    
    void getScores(int numScores,float* array1)
    
    
    { int i;
     int numScores1;
         for (int i=0;i<numScores1;i++)
        {
             do 
             { 
             cout << " Please enter your 1st score now: " << endl;
             cin >> array1[i];
              } while (array1[i] > 100 && array1[i] < 0);
         
         }   
    }
    void sortArray1(float array1[], int elems)
    {
        bool swap;
        float temp;
        do
        {
            swap = false;
            for (int count = 0; count < (elems - 1); count++)
            {
                if (array1[count] > array1[count + 1])
                {
                    temp = array1[count];
                    array1[count] = array1[count + 1];
                    array1[count + 1] = temp;
                    swap = true;
                }
            }
        } while (swap);
    }
    float median1( float array1,int numScores)
    {
        float median;
        int numScores1;
    
    
        if (numScores1 %2 !=0)
            
            {
                median = (sortArray1[numScores1/2]+ sortArray1[numScores1]/2-1])/2);
    
    
             }
        else 
            {
                median = (sortArray1[numScores1/2]);
            }
        return median;
    }
    void output1(float array1, float median, int numScores)
    { 
         int median;
         cout <<"Median score is " << median << endl;
    }

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    12
    PLease copy and run code, idk what to change.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    PLease copy and run code, idk what to change.
    No, you need to tell us what is wrong with the code. How should we know what your trying to accomplish?

    If you get compile errors post the complete error messages, exactly as they appear in your development environment.

    Jim

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You need to fix indentation. Select a common indentation style and stick with it (eg Allman).

    >>sortArray1(array1[],elems);
    This is not how you pass an array.

    >> int numScores1;
    >> float* array1;
    >> array1=new float[numScores1];
    You don't need to declare variables on a separate row, or at the beginning of a function. You can declare them anywhere and initialize them at the same time, eg
    float* array1=new float[numScores1];
    Although, that is irrelevant in this example.
    numScores1 is uninitialized, so you are creating an undefined amount of new floats.
    Still, you should be using std::vector instead of new to create your arrays. Researching that is part of your homework.


    There is also a function named swap in the standard library. Unless you have toll out your own, I suggest you use it.
    There is also a function named sort in the standard library. Unless you have toll out your own, I suggest you use it.

    Finally, you need to fix your arrays, so I highly recommend you read SourceForge.net: Safer arrays in Cpp - cpwiki.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    PLease copy and run code, idk what to change.
    Absolutely not - show some more effort when asking for help - That is a DREADFUL question - dumping a load of code without any indication of what you're problem is!! do you know how much it would cost you per hour in a commercial environment to get help from some of the people that volunteer time here? Have some sense, and manners
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. errors
    By juice in forum C++ Programming
    Replies: 16
    Last Post: 02-07-2012, 03:11 AM
  2. HELP with DX9 Errors!!!
    By Tommaso in forum Game Programming
    Replies: 7
    Last Post: 06-28-2006, 02:51 PM
  3. Help with ISO errors
    By alpha22 in forum C++ Programming
    Replies: 9
    Last Post: 02-18-2006, 05:10 PM
  4. Can't see errors, can you?
    By stustu92 in forum C Programming
    Replies: 4
    Last Post: 02-01-2006, 06:11 AM
  5. errors.. errrors.. more errors
    By Klinerr1 in forum C++ Programming
    Replies: 17
    Last Post: 07-23-2002, 08:43 PM