algorithm workbench: writing a statement

hi,

a program contains the following function:

int cube(int num)
{
return num * num * num;
}

I'm suppose to write a statement that passes the value 4 to this function and assigns its return value to the variable result, but im not sure what write in for the statement.

thank you,
may
Check your book for an example of how to use a function and test it out, it's pretty simple.
Very hard to explain how to do this without actually giving you the answer.. it's INCREDIBLY simple stuff. Basically I just wrote out a code below and commented it so you can see how it works. Read through that code and you should easily be able to figure out how to solve your problem.
1
2
3
4
5
6
7
8
9
10
11
//This sets up a new integer with the variable name "myVariable"
int myVariable;

//This initializes myVariable using the function MyFunction() [note it has no parameters]
myVariable = MyFunction();

//Setup a function called "MyFunction" with 0 parameters and ALWAYS returns (10)
int MyFunction()
{
      return (10);
}


You should be able to see that myVariable will = 10 after this code is executed. All you have to do is change MyFunction() to your own and change myVariable to call your function with your own parameters. Hope that helps and I really hope you understand, because it's really easy stuff! ;)
Last edited on
Topic archived. No new replies allowed.