Help with Programming

Hello. I am a beginner in programming and wanted to know if someone can help. I have no idea what I am doing or where to even start. If anyone can help me on where to begin I would appreciate it. Here is the assignment.

What does the following program do?. Copy the sample program and compile it, then find the results. Submit a report which is more than one page length to explain how the program works and how you can improve it.

The problem is I don't even know what is wrong with the program? I understand that it adds up all the numbers but am I supposed to put in the program that it is supposed to add up the numbers?

#include <iostream>
using std::cout;
using std::endl;

int whatIsThis( int [], int ); //funtion prototype

int main()
{
const int arraySize = 10;
int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

int result = whatIsThis( a, arraySize);

cout << "Result is" << result << endl;
return 0; //indicates succesful termination
} // end main

// What does this function do?
int whatIsThis( int b[], int size)
{
if ( size == 1 ) // base case
return b [ 0 ];
else // recursive step
return b [ size - 1 ] + whatIsThis( b, size - 1 );
} //end function whatIsThis
Last edited on
closed account (48T7M4Gy)
Try out changing the number (and size even) of elements in int a[] and then running the program. It's a dead give away if you just have {1,2,3} if you don't get confused with factorials or perfect numbers, that is.
closed account (48T7M4Gy)
BTW double posting is very bad etiquette here.

http://www.cplusplus.com/forum/windows/176924/
closed account (48T7M4Gy)
Triple post:
http://www.cplusplus.com/forum/beginner/176922/
http://www.cplusplus.com/forum/windows/176924/
http://www.cplusplus.com/forum/general/176928/

That's a seldom seen trifecta.
Ok thank you. I will try that. Sorry for the triple posts, I was not sure where exactly to post.
closed account (48T7M4Gy)
That's OK. Apology accepted. :)

You really should try playing around with the data. Eric is right but testing the data produces a good result too.

If his theory is right 1,2,3,4 should get you 10.

:)
Topic archived. No new replies allowed.