I am a beginner in C, and am currently learning about using multiple functions.
A piece of my current assignment is to get 3 values from a function I call "Menu();", but later, another two from another function I call "total();" and use them in function "show();".
This is all well and good, but I have to get the values from "total();" into "show();" in two seperate calls after already assigning some variables to "show();" in a seperate function.
How can I go about doing this? Keep in mind, I am brand new to multi-functions, so please be kind.
Sorry if this is hard to understand, I haven't picked up much Programming Lingo.
I'm certain that this part of your assignment can be done using the values that functions can return, and functions' parameter lists. I'll explain this to you in about as much detail as you need.
If you take any old function:
A function's body, contained in curly braces, are the statements the function will execute.
long int calc ( int v )
/** some calculation **/
/** return the result as a value **/
return v * 2;
/** ... **/
int x = getint( );
long int total = calc( x );
A function's parameters are values it operates on.
An optional return value stores the result of the process.
To explain this briefly: say you get a value for x, and in this case it's 30. If we examine the parameter list for calc(), we discover that it takes an int as a parameter. As we know, thirty is an int so this is perfect.
I can easily demonstrate how a function in general works by calling calc() with x. calc() operates it's value v, which is now a copy of x's value. It doubles v, storing the result in total. So a function can use values going in as parameters, do something with them, and return the result to where it was called.
Knowing this, you may want to review functions in your textbook, and then start your homework.