New to C++ but not entirely to programming. I am stuck on this one problem. This function is called within a loop that has constantly updating ‘c’ values. I want to keep the scope of the storedVal var within the call but don’t want to initialize it each time. How can I declare it properly?
void fun(float a[], float c){
float storedVal = (0.0f); //"on" is a global bool
if (on) {
storedVal = c;
on = false;
}
else if (c-storedVal > 0.5) {
a[0] = storedVal;
}
}
in this example each time on = true, I want it to update storedVal. But isn’t this just iterating through storedVal = 0?