Link Functions

Write your question here. Okay my problem is linking two functions; i.e getting
a value from the first function and adding it to a second, totally different function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  int NumberAnimals(int Animals)
{
    cout<<"How many animals are present:";
    cin>>NumAnimals;
    
    return NumAnimals;
}

int Addition(int Add)
{
    int Add = NumAnimals * 4;
    cout<<"Your total is;"<<Add<<endl;
    
    return Add;
}

what I want to do is get the value from the first function(NumAnimals) and place it
in the second function.

any help....much appreciated.
The parameter of NumberAnimals() is unused.
The local variable on line 11 is hiding the parameter 'Add' of the function.
1
2
3
4
5
int num = NumberAnimals(someInt);
int result = Addition(num);

// You can also chain calls like this
result = Addition(NumberAnimals(someInt));
Last edited on
Topic archived. No new replies allowed.