Functions and the main

Alright, I have a function,

1
2
3
4
5
6
7
  int NumberAnimals(int Animals)
{
    cout<<"How many animals are present:";
    cin>>NumAnimals;
    
    return NumAnimals;
}


What I want to do is get the value from this function(NumAnimals) and implement it in my main. eg.

int main(){

if(Cows = Pigs){
cout<<NumAnimals<<"Are there";
}
else{
.
.
.
You'd want to call the function, and store it into a variable. Also, your function asks for an integer Animals that is never used. And you used assignment instead of equality check.

In all seriousness, the only time you can actually get access to a variable declared inside of a function, from outside of the function; is to return the address of the variable itself and create a pointer towards it, thus gaining access to the variable in its entirety.
Topic archived. No new replies allowed.