variable modification inside functions
Hello,
I am trying to find a way to let functions edit variables outside of main(). Is there anyway to do this?
My code currently look like this
Code:
#include <iostream>
using namespace std;
int Runme(int y, int z);
int main()
{
int y; y = 0; //define variables
int z; z = 0;
int a; a = 0;
cin>> y;
cout<<"\n"<<y<<"\n";
Runme(y, z);
cout<<"\n"<< y <<" "<< z;
cin >> a;
}
int Runme(int y, int z)
{
cin>>z;
cout <<"\n"<<y<<" "<<z;
y = y + z;
cout <<"\n"<< y <<" "<< z;
return y, z;
}
If you complie this, you'll notice the last cout statement shows int y and z as they are in main, not with the last input recived from Runme()...
Is there anyway for function Runme() to pass it's variables back to main()? What would someone recommend I do when trying to work with variables inside main() like this?