Demo Program for Style 4
non-void functionName(argument(s))

// Example program  

#include <iostream.h>
#include <stdlib.h>

double timesTwo(double num);   // function prototype

int main(void)
{
     system("CLS");

     double number, response;
     cout<<"Please enter a number:";
     cin>>number;
     response = timesTwo(number);  //function call
     cout<< "The answer is "<<response;
     return 0;
}
//timesTwo function
doubel timesTwo (double num)
{
     double answer;   //local variable
     answer = 2 * num;
     return (answer);
}
 
Notice how the variable in the function (num) does not have the same name as the variable sent to the function (number).  It makes no difference what the variables are called, as long as they are of the same variable type.  Variables are used in the order in which they are sent to the function.

 

 Return to Topic Menu | Computer Science Main Page | MathBits.com | Terms of Use