Variable not accessible within and if statment

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-04-20T14:51:23Z Indexed on 2010/04/20 14:53 UTC
Read the original article Hit count: 184

Filed under:
|
|

I have a variable which holds a score for a game.

My variable is accessible and correct outside of an if statement but not inside as shown below

cout << score << endl; //works
    if(!justFinished){
        cout << score << endl; // doesn't work prints a large negative number
        endTime = time(NULL);
        ifstream highscoreFile;
        highscoreFile.open("highscores.txt");
        if(highscoreFile.good()){

            highscoreFile.close();
        }else{
            std::ofstream outfile ("highscores.txt");
            cout << score << endl;
            outfile << score << std::endl;

            outfile.close();
        }

        justFinished = true;
    }
    cout << score << endl;//works

© Stack Overflow or respective owner

Related posts about c++

Related posts about variables