Improving program

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 #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 
Last edited on
looks more like a "what keeps this code from compiling" question to me
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.
Everything is capitilized.

Its not Int, its int.
Its not Const, its const.
Its not Cout, its cout.
Its not If, its if.
Its not Return, its return.
Its not Else, its else.

And your code snippet is completely un-compilable.

Edit: Just to clarify. I know its probably not what its suppose to look like, Im just responding to this

So I've already edited this post twice because I messed up typing it in.


Becuase its still kinda messed up :D
Last edited on
Judging from line 20 and the function name, I think you're supposed to change the program to use iteration, not recursion. (IE use a loop)

@TarikNeaj
He probably typed it in Word or some other word processing program, which is why the first letter in every line ended up capitialized.
Last edited on
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?
It wont run when you copy paste it into visual studio. Becuase everything is capitilized. Ive tried it myself^^

You're gonna have to make the changes I showed.
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.

http://www.cplusplus.com/forum/beginner/1988/

Also, @Duoas (one of the experts here) wrote an article about why it is evil, read it here if you like -

http://www.cplusplus.com/articles/j3wTURfi/
Topic archived. No new replies allowed.