944,044 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1713
  • C++ RSS
Feb 27th, 2006
0

home work help please

Expand Post »
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 <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;
}



this is error i getompiling...
program8.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\project8\program8.cpp(15) : warning C4101: 'array1' : unreferenced local variable
C:\Program Files\Microsoft Visual Studio\MyProjects\project8\program8.cpp(26) : error C2061: syntax error : identifier 'array'
Error executing cl.exe.

project8.exe - 1 error(s), 1 warning(s)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
candykane69 is offline Offline
2 posts
since Feb 2006
Feb 27th, 2006
0

Re: home work help please

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++.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Feb 27th, 2006
2

Re: home work help please

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++.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Feb 27th, 2006
0

Re: home work help please

thank you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
candykane69 is offline Offline
2 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: assignment operator for a 3d array
Next Thread in C++ Forum Timeline: C++ homework Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC