954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

home work help please

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.


#include

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]

candykane69
Newbie Poster
2 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

Those are exceptionally detailed and clear diagnostic messages. What's the problem? 'array1' isn't used and 'array' isn't expected where you put it. Both fixes require no more than a remedial knowledge of C++.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

candykane, the first is a warning, which means your code is not technically incorrect there. But you have a variable named 'array1', which you aren't using for anything at all! The compiler, being nice and friendly (in a sarcastic sort of way) is telling you this, since maybe it means you made an error, or just have code that could use some cleaning.

The second error is a syntax error (as the compiler informs you). 'if' branches do not use that sort of syntax in C++.

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

thank you

candykane69
Newbie Poster
2 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You