Output variable in function - C++ Function

C++ examples for Function:Function Creation

Description

Output variable in function

Demo Code

#include <iostream>
#include <cstdlib>

using namespace std;

int myFunc1(int original)
{
    int result = original * 2;
    result = result + 10;/*  ww  w  .  j  a va 2s .co  m*/
    result = result * 4;
    cout << "Calculating " << result << endl;
    return result * 10;
}

int myFunc2(int original)
{
    int result = original + 10;
    result = result - 2;
    cout << "Calculating " << result << endl;
    return result;
}

int main()
{
    int rabbits = 5;
    int antelopes = 5;

    rabbits = myFunc1(rabbits);

    cout << "Rabbits now at " << rabbits << endl;

    antelopes = myFunc2(antelopes);

    cout << "Antelopes now at " << antelopes << endl;

    return 0;
}

Result


Related Tutorials