Pages

Thursday, 22 February 2018

Return Type of a Function in C++ Programming Language

Return Type of a Function in C++ Programming Language

#include <iostream>
  using namespace std;
 
  int timesTwo(int num);   //  function prototype
  int main()
  {
     int number, response;
     cout<<"Please enter a number:";
     cin>>number;
     response = timesTwo(number);  //function call
     cout<< "The answer is  "<<response;
     return 0;
  }

  //timesTwo function
  int timesTwo (int num)
  {
     int answer;   //local variable
     answer = 2 * num;
     return (answer);

  }