#Just need some help understanding functions

22 messages · Page 1 of 1 (latest)

sinful crystal
#

Hey, I am relatively new to c++ and I have just moved on to functions in the tutorial I am following but I don't really understand them. Specifically I am following along with the banking practice problem and the top part I really dont understand. The code will be below for anyone who wouldn't mind helping.

Part I dont understand

void showBalance(double balance);
double deposit();
double withdraw(double balance);
silent sunBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

young valley
#

Those are function declarations, they declare the existence of the functions.

sinful crystal
#

So the first line is a function and in the part in the brackets tells the function what it can use?

young valley
#

No, the first line declares the existence of a function called showBalance that takes in a double argument.

dusk olive
#

What datatype you can pass*

sinful crystal
young valley
#

Take any double value, the name there doesn't have much technical meaning at that location.

#

When you have a function definition then the name will become a variable containing that passed value.

sinful crystal
#

Ahh ok that makes more sense, what about the second line then? Ist hat just a varible called deposit inside the showbalance function?

young valley
#

It declares a function called deposit that doesn't take any arguments.

#

The three lines are separate statements.

sinful crystal
#

If it doesn't take any arguments what does it actually do then?

young valley
#

It can still do anything, just that it doesn't need the caller to pass anything.

#

It may retrieve the data it needs from somewhere else.

sinful crystal
#

So it can take in any data and do whatever it wants with it?

young valley
#

It doesn't take data from the caller.

sinful crystal
#

Oh ok so its just a function that returns a value as a double then I am guessing

young valley
#

Yes.

sinful crystal
#

And for the last function its just the same as the first function pretty much

#

Well thats been cleared up a lot thank you very much!

#

!solved