dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: What am I missing?

  1. #1
    Join Date
    Dec 2008
    Posts
    8

    What am I missing?

    I get a pointer error when compiling.

    #include <iostream>
    #include <cstdlib>
    using namespace std;

    void sort (int, int);

    int main ()
    {
    int total = 0.0, average;
    int numscores, counter;

    cout << "Enter number of test scores: ";
    cin >> numscores;

    int *scores = new int[numscores];

    for (int counter = 0; counter < numscores; counter++) // Enter values
    {
    do
    {
    cout << "Enter test score " << (counter + 1) << ": ";
    cin >> scores[counter];
    if (scores[counter] < 0)
    {
    cout << "Invalid entry! ";
    cout << endl;
    }
    } while (scores[counter] < 0);
    }
    cout << endl;

    sort(scores, numscores);

    for (int counter = 0; counter < numscores; counter++) // total
    total += scores[counter];

    average = (total / numscores); // average

    for (counter = 0; counter < numscores;counter++) // Print scores
    {
    cout << scores[counter] << endl;
    }
    cout << endl;
    cout << "Average: " << average << endl;

    system("pause");
    return 0;
    }

    void sort (int tests[], int numtests)
    {
    int temp, count;
    bool swap;

    do // Sort
    {
    swap = false;
    for (int count = 0; count < (numtests - 1); count++)
    {
    if (tests[count] > tests[count - 1])
    {
    temp = tests[count];
    tests[count] = tests[count + 1];
    tests[count + 1] = temp;
    swap = true;
    }
    }
    } while (swap == false);
    }

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: What am I missing?

    I get a pointer error when compiling.
    Do we have to guess which one ?

    btw. .. this doesn't give you a average. Divisions like these only work when you use type 'double' as variables.
    Code:
    average = (total / numscores); // average

  3. #3
    Join Date
    Dec 2008
    Posts
    8

    Re: What am I missing?

    the error comes from the scores pointer

    Thanks.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: What am I missing?

    Code:
    void sort (int, int);
    void sort (int tests[], int numtests)
    These are not the same.

  5. #5
    Join Date
    Jun 2005
    Posts
    315

    Re: What am I missing?

    What exactly is the error(s)?

  6. #6
    Join Date
    Dec 2008
    Posts
    8

    Re: What am I missing?

    error C2664: 'sort' : cannot convert parameter 1 from 'int *' to 'int'
    1> There is no context in which this conversion is possible

  7. #7
    Join Date
    Dec 2008
    Posts
    8

    Re: What am I missing?

    Lindley,

    Thank you. It seems that adding the [] in the prototype did the trick.

    Scott

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)