One error with pointers

This is a discussion on One error with pointers within the C++ Programming forums, part of the General Programming Boards category; I need help with pointers, I am getting the following error: error C2664: 'showArray' : cannot convert parameter 1 from ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    22

    One error with pointers

    I need help with pointers, I am getting the following error:

    error C2664: 'showArray' : cannot convert parameter 1 from 'int *' to 'int *[]' for both of these functions:

    Code:
    void sort(int *[], int);
    void showArray(int *[], int);
    I have run out of ideas, please help!

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    //Function prototypes
    int getnumtestscores();
    void gettestscores(int[], int);
    void sort(int *[], int);
    void showArray(int *[], int);
    double average(int [], int);
    
    
    int main()
    {
    	int numts = getnumtestscores();
    
    	int *testscores;
    		
    	testscores = new int[numts];		//To dynamically allocate an array
    
    	gettestscores(testscores, numts);
    
        cout << "The average of all " << numts << " test scores is: " 
             << fixed << showpoint << setprecision(2)
             << average(testscores, numts);
    
    	cout << "The testscores are: " << showArray (testscores, numts);
    	cout << "The numbers sorted are: " << sort (testscores, numts);
    
        // Free dynamically allocated array in memory
        delete [] testscores;
        // Make scores point to null
        testscores = 0;
    
    	return 0;
    }
    
    int getnumtestscores()
    {
        int num;
    
        cout << "\n How many test scores do you want to enter : ";
        for(;;) // loop forever  ... until return
        { 
            cin >> num;
         
            return num;
        }  
    }
    
    void gettestscores(int testscores[], int numts)
    {
    	cout << "What are the testscores for the students?\n";
    
    	for (int count = 0; count < numts; count++)
    	{
    		cout << "Testscore " << setw(2) << (count+1) << ":";
    		cin >> testscores[count];
    
    		if (testscores < 0)		//Input validation
    		{
    			cout << "An invalid score was entered, please enter a score more than 0\n";
    		}
    	}
    }
    
    void sort(int *array[], int numts)
    {
    	int lowIndex, *lowest;
    
    	for (int count = 0; count < (numts-1); count++)
    	{
    		lowIndex = count;
    		lowest = array[count];
    		for (int index = count + 1; index < numts; index++)
    		{
    			if (*(array[index]) < *lowest)
    			{
    				lowest = array[index];
    				lowIndex = index;
    			}
    		}
    		array[lowIndex] = array[count];
    		array[count] = lowest;
    	}
    }
    
    void showArray(int *array[], int numts)
    {
    	for (int count = 0; count < numts; count++)
    		cout << *(array[count]) <<" ";
    	cout << endl;
    }
    
    double average(int *array[], int numts)
    {
    	int total = 0, *testscores;			//Accumulator
    	double average;						//To average testscores
    
    	for (int count = 0; count < numts; count++)
    	
    		total +=testscores[count];
    
    	  return total/numts;
    }

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,272
    testscores is an int pointer. Yet you are trying to pass it as a pointer to an int pointer.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,262
    Code:
    	for (int count = 0; count < numts; count++)
    	{
    		cout << "Testscore " << setw(2) << (count+1) << ":";
    		cin >> testscores[count];
    
    		if (testscores < 0)		//Input validation
    		{
    			cout << "An invalid score was entered, please enter a score more than 0\n";
    		}
    	}
    Your input validation needs some help. It doesn't help to validate the input after you place the input into the array.

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    22
    Thank you, but I am not sure if I fully understand the concept for that, I am assuming that you meant that these two function calls are incorrect:

    Code:
    	showArray (testscores, numts);
    	sort (testscores, numts);
    Can you provide me with an example as to what it should look like?
    Last edited by musique; 05-01-2009 at 07:44 PM.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    22
    Thanks bithub, I would work on my input validation as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 06:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 11:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21