Here is the error:

cannot convert parameter 1 from 'int *' to 'int *[]'

here is my code:

#include <iostream>
using namespace std;

void findMode( int *, int, int);
void selectionSort(int *[], int);

int main()
{
	int *numbers;	//dynamically allocate an array
	int elements,		//holds the number of inputs
		count,			//counter
		largest = 0;	//largest input	

	//get the amount of numbers being calculated
	cout << "How many numbers do you wish in input?";
	cin >> elements;

	//Dynamically allocate anarray large enought to hold
	//the amount the uder had input
	numbers = new int[elements];

	//enter the numbers being calculated
	cout << "Enter the numbers you would like to find the mode of: \n";
	for (count = 0; count < elements; count++)
	{
		cout << "Intput number " << (count +1) << ": ";
		cin >> numbers[count];
	}

	//find the largest number
	for (count = 0; count < elements; count++)
	{
			if ( *(numbers + count) > largest)
				largest = *(numbers +count);
	}

	//Sort the values
	[B][U]selectionSort(numbers, elements);[/U][/B]
	//find the mode
	findMode(numbers, elements, largest);
	return 0;
}


//***********************************
//takes in the array of numbers and *
//Sorts the numbers in ascending    *
//order in the array                *
//***********************************

void selectionSort(int *array[], int size)
{
	int startScan, minIndex;
	int *minElem;

	for (startScan = 0; startScan < (size-1); startScan++)
	{
		minIndex = startScan;
		minElem = array[startScan];
		for(int index = startScan + 1; index < size; index++)
		{
			if (*(array[index]) < *minElem)
			{
				minElem = array[index];
				minIndex = index;
			}
		}
		array[minIndex] = array[startScan];
		array[startScan] = minElem;
	}
}

void findMode(int *array, int size, int large)
{
	int array2[large];
	int count;
	int x;
	int mode = 0;

	for (count = 0; count < size; count++)
	{
		x = array[count];
		array2[x] = array2[x]++;
	}

	for ( count = 0; count < size; count++)
	{
		if (array2[count] > mode)
		mode = count;
	}

	cout << "The mode is: " << mode << endl;
}

the error says it conflicing but im not sure what to change to make it work

Are we supposed to guess which line out of 95 the error occurs on? We have slightly more than a 1% chance of that... :icon_wink:

LOL

i thought i highlighted it was red... my mistake

When it refers to
selectionSort(numbers, elements); is when i get the error on line 41

i believe i must not be calling the void statement correctly or something of that nature

What you need to change is line 7 and line 53 like follows:
7: void selectionSort(int *, int);
53: void selectionSort(int array[], int size)

The idea is that an array is already considered a pointer, so writing "array[]" is the same as "*array" in line 53 ;)

Cheers!

No, you're not calling the sort function according to its parameters.

void selectionSort(int *array[], int size)

However, it's the parameter that is wrong. Why do you have an asterisk in the array parameter?

And why is minElem in the sort function a pointer?
Val

≥≥ And why is minElem in the sort function a pointer?

it how the book had it, so i made it that way. =/ that would chunk was taken fro the book.


I went ahead and made the changes with
>> 7: void selectionSort(int *, int);
53: void selectionSort(int array[], int size)

and i even changed minElem from a pointer. but now i get this error: "illegal indirection" for line 70

I'm tempted to advise you to chuck that book out. That sort was not correctly written.

Here's how it should be:

void selectionSort(int array[], int size)
{
	int startScan, minIndex;
	int minElem;

	for (startScan = 0; startScan < (size-1); startScan++)
	{
		minIndex = startScan;
		minElem = array[startScan];
		for(int index = startScan + 1; index < size; index++)
		{
			if (array[index] < minElem)
			{
				minElem = array[index];
				minIndex = index;
			}
		}
		array[minIndex] = array[startScan];
		array[startScan] = minElem;
	}
}

Val

error C2143: syntax error : missing ';' before '<' on this line "if (array[index] < minElem)"

i actually tried to do it this way a couple of attempts back, but why its asking me to add the ; before <...... i have no clue

Please post your full code - there might be something wrong somewhere above that line that puts the compiler out of sync.

#include <iostream>
using namespace std;

void findMode( int *, int, int);
void selectionSort(int *, int);

int main()
{
	int *numbers;	//dynamically allocate an array
	int elements,		//holds the number of inputs
		count,			//counter
		largest = 0;	//largest input	

	//get the amount of numbers being calculated
	cout << "How many numbers do you wish in input?";
	cin >> elements;

	//Dynamically allocate anarray large enought to hold
	//the amount the uder had input
	numbers = new int[elements];

	//enter the numbers being calculated
	cout << "Enter the numbers you would like to find the mode of: \n";
	for (count = 0; count < elements; count++)
	{
		cout << "Intput number " << (count +1) << ": ";
		cin >> numbers[count];
	}

	//find the largest number
	for (count = 0; count < elements; count++)
	{
			if ( *(numbers + count) > largest)
				largest = *(numbers +count);
	}

	//Sort the values
	selectionSort(numbers, elements);

	//find the mode
	findMode(numbers, elements, largest);
	return 0;
}


//***********************************
//takes in the array of numbers and *
//Sorts the numbers in ascending    *
//order in the array                *
//***********************************

void selectionSort(int array[], int size)
{
	int startScan, minIndex;
	int minElem;

	for (startScan = 0; startScan < (size-1); startScan++)
	{
		minIndex = startScan;
		minElem = array[startScan];
		for(int index = startScan + 1; index < size; index++)
		{
			if (array[index]) < minElem)
			{
				minElem = array[index];
				minIndex = index;
			}
		}
		array[minIndex] = array[startScan];
		array[startScan] = minElem;
	}
}

void findMode(int *array, int size, int large)
{
	int array2[large];
	int count;
	int x;
	int mode = 0;

	for (count = 0; count < size; count++)
	{
		x = array[count];
		array2[x] = array2[x]++;
	}

	for ( count = 0; count < size; count++)
	{
		if (array2[count] > mode)
		mode = count;
	}

	cout << "The mode is: " << mode << endl;
}

Oh, you should have found this yourself!

if (array[index]) < minElem)

See the closing parenthesis that does not belong in this line???:twisted:

This article has been dead for over six months. Start a new discussion instead.