0

Greetings:

I am taking my first C++ class and am a little stuck. I keep receiving three compiler errors, but I can't seem to figure them out. Can someone please point me in the right direction.

The assignment is:

Write a C++ program having a recursive function recursiveMinimum that takes an integer array and the array size as arguments and returns the smallest element of the array. The function should stop processing and return when it receives an array of 1 element.

I am attaching my .cpp file.

Thanks to anyone that can assist me.

By the way, God bless all you gurus. If this is a beginner's class, I hate to see the advanced classes.

Attachments
//Minimum array value
//Week 8 assignment

#include <iostream>

int recursiveMinimum(int[], int);
int smallest, index;

int main()
{
	int x=10;
	int array1[10];
	smallest=0;
	index=0;

return 0;
}


int recursiveMinimum(int[] array, int size)
{
	if size<=1 return -1;
	if array[index]<smallest
		smallest=array[index];
	index++;
	recursiveMinimum(array, size);
	return smallest;
}
3
Contributors
2
Replies
3
Views
13 Years
Discussion Span
Last Post by Chainsaw
0

>I am attaching my .cpp file.
Don't do this. Post the code. If the code is too long, post relevant pieces. Your attachment is very small, so the code is short enough to post.

0

You were doing fine up until this routine:

int recursiveMinimum(int[] array, int size)
{
	if size<=1 return -1;
	if array[index]<smallest
		smallest=array[index];
	index++;
	recursiveMinimum(array, size);
	return smallest;
}

1) should be int array[] not int[] array
2) if statements always have their argument in parens, like "if (size <=1) return -1;"

Next time, please post the exact error message too so we don't have to play compiler for you. :-)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.