Before I get into it, a HUGE shout out to my friends Sam & Brian who helped me figure out some of the final bugs in my last program. I got 5/5 on the assignment. (Yeay) -- my professor noted that my indentation was not accurate and I had one redundant note to the program, but she led that slide this time. Phew.
Ok, so this week's assignment, posted in the last entry, is about functions.
I am supposed to write a program that --
1) asks user how much she will put into savings account
2) asks user what the annual interest rate is
3) ask user how long she'll be leaving the money in the savings account
4) tell the user how much money they will have at the end of that period
Ok, sounds simple enough. I could do that WITHOUT functions, but that's not the assignment. So...
My program must define and use a function that performs this calculation.
According to the formula to do that given in class yesterday, I need to...
1) write function call for the function you haven't written yet
2) draw box with the parameters and return types
3) write prototype AND comment for what it's doing
4) write the full function definition
(half of that is still not English to me, so I'm going to take this one step at a time.)
Of course in the assignment, my teacher gave us the prototype (which is supposed to be STEP 3) so... I don't know if that's good or bad. The whole assignment instructions contradicts the professors order of doing this. Eeks.
OK, I'm just going to do this the way she said to in class... because this type of question is apparently going to be on the midterm.
1. Write a function call for the function you haven't written yet
First... what's a function call?
The way to use a function is with a "function call" expression, which consists of the function name followed by a list of "arguments" in parentheses. Another explaination: A function call is an expression containing the function name followed by the function call operator, (). If the function has been defined to receive parameters, the values that are to be sent into the function are listed inside the parentheses of the function call operator. The argument list can contain any number of expressions separated by commas. It can also be empty.
Say What?
Ok. So, what are parameters?
"Parameters provide a simple mechanism for defining and setting the valuesof inputs that are required by a form at startup. Form parameters are variables of type char,number,date that you define at design time." -- GeekInterview
Or, from my class notes: "parameter is a local variable that gets initialized with the function call"
(Still greek to me, but let's move on...)
ok. So. I think it goes:
functionName (function call operator: list parameters (variables) here)
For this assignment, then, that's...
Well, this is the prototype not the function call, so I'm confused, but anyway...
double futureInvestmentValue (double investmentAmount, double monthlyInternetRate, it years);
More later...
No comments:
Post a Comment