God O' God, please help thee!

Started by
13 comments, last by Stormrage 20 years, 10 months ago
sumSequence takes integers input by the user, and for each number it squares the number than adds it to the accumulator. Once you enter a neg. number it stops and returns the value of the accumulator (sum of the squares of all the number input by the user).

Arguments are the values you can pass into a function. In the sumArray function, it can except an array of integers (integerArray[]) and an integer (sizeOfloatArray). You write your function to perform operations on these values. When you call a function from your main program you "pass in" values. In your original ex. the array created from the data you input and its size are passed in to the function. When the computer executes the code for the function it replaces the, in this example, integerArray[] and sizeOfloatArray variables with the ones you passed in.
"If I only had 6 months left to live I'd get back together with my first wife, because 6 months with her would be like an eternity." -Bobby Hall
Advertisement
HALLEJUAH! HALLEJUAH! I get it! I truly get it! Thanks so much, this issue was really bothering me and now my progress is smooth again! Thanks a lot all of you for taking the time to answer all my questions :D :D :D
numSequence is more of an arbitrary subdivision in this case (blame it on the writer of the code). Here''s a quick explanation of functions:

double square(double doubleVar) {  return doubleVar * doubleVar;}// some time laterdouble someVar = square(someOtherVar);


In this example the function goes by the name "square", which describes its purpose fairly well as this function returns the inputed value squared. Picture the lines before the comment (the actual function definition) as a miniature program. This "program" is called when you write "square(someOtherVar)". Behind the scenes (you could say) doubleVar is assigned someOtherVar''s value (i.e. doubleVar = someOtherVar), then the code inside the {}''s is executed. This function takes the variable doubleVar and squares it (doubleVar*doubleVar = doubleVar2). Then comes the important part. The function then takes this value and returns it to the expression that called it (where in this case it gets assigned to a variable). This is the purpose of the return statement. So in the end the whole example is basically equivalent to:

double someVar = someOtherVar*someOtherVar;


I hope that gives you some idea as to whats going on in a function. BTW, here is a good place to learn C++.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________

int array10[10] = {3,6,12,24,48,96,192,383,768,1536};

this declares the array "array10" with 10 parts available to hold values and assigns values to all ten parts.

There are actually 11 parts, but only 10 are able to hold values that you may define. array10[0] thru array10[9] (ten parts are the ones you may use. array10[10] is "\n" that is the NULL terminater that tells the compiler that this is the end of the array. If you try to access or call array10[10] you will get an error.
I AM an Army of One... I just have 10,000 other Armies of One to back me up!
quote:Original post by Stormrage
HALLEJUAH! HALLEJUAH! I get it! I truly get it! Thanks so much, this issue was really bothering me and now my progress is smooth again! Thanks a lot all of you for taking the time to answer all my questions :D :D :D


Good for you! This stuff can be tricky. You''ll probably have smooth sailing until you start learning about pointers, at which point you''ll probably come back here for more help

This topic is closed to new replies.

Advertisement