Q:

storing value Turbo C++

I am currently trying to get my program to store a value so that it can display that value whenever there is an error. Here is my program :
void function()
{
    float abc[2];
    int i = 0;
    if ( i/2 != 0 ) 
    { 
      i++; 
      abc[0] = 1; 
    }
    abc[1] = abc[0];
    cout << abc[1];
}

Practically, my program keeps calling this function until I exit it, so it will keep updating my program and show me abc[1]. What I want is when the condition of the if statement is not met, abc[1] will display the previously known value of itself. How do I do it?.

A:

I'm not sure exactly what result you are trying for, but you need to make abc and i static, thusly:
void function()
{
    static float abc[2];
    static int i = 0;
    if ( i/2 != 0 ) { i++; abc[0] = 1; }
    abc[1] = abc[0];
    cout<<abc[1];
}

This will allow them to retain their value between function calls.  Right now that function is pretty silly, but I don't know what to recommend because I don't know what you are trying to do.

