#include <iomanip>
usingnamespace std;
int main (){
int y = 1;
int n = 0;
cout<<"would you like to perform a computation? ";
cin>>answer;
if (answer = 1){
function()
}
elseif (answer = 0){
exit(0);
}
}
function(){
int variable;
cout<<"input variable for random calculations: ";
cin>>variable;
cout<<variable<<"squared is: "<<variable * variable;
//I would like to have some way to reset variable right here so that when it's called
//again in the redo function it doesnt loop the final cout statement of the function()
redo()
}
redo(){
cout<<"would you like to do this again? ";
cin>>yesNo;
if (yesNo = 1){
function(); //
}
else(){
exit(0);
}
}
In this code, every time function is called, a whole new int variable is created. A whole new one. Any int variable from a previous call to function has no effect whatsoever.
I found my issue then! Thanks Moschops. I had my variable set as a global rather than inside my function so it was never reverting back to the originally undefined variable.