So to start off this is a project for a class. The assignment is to explain what the code does and then make improvements. I generally understand what the program does but don't get what is meant by improving it. It works fine. Why would I change it? Any hints on what I should look to improve when reading programs would be appreciated.
#include <iostream>
Using std: :cout;
Using std: :endl;
Int whatIsThis( int [], int ); //function 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 successful 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
So I've already edited this post twice because I messed up typing it in. Go figure. If I've missed something else I just entered it wrong. The program definately works when compiled.
Thanks, that makes sense
When you say it won't compile what do you mean? If I copy paste it on visual studio it runs when I debug, from what I understand that's compiling it right?
I fixed all of that, I only ask because it was mentioned once before to me when I had somebody look at a program. Could a system(pause) cause that. From what I here, don't do system pause but I did back then and was wondering. Thanks for the feed back btw.
Then its alright :) Yes, You really dont want to use system pause, there's many other ways of achieving what it does. There is an huge thread about that.