Question: I keep getting this error in my code, uninitialized local variable "name" used. I set a variable like this 

> 
> int name = 0;
> 
> 
> 

then later on in the code,

> 
> int name = name + 1;
> 
> 
> 

I am trying to set name to 0 then later on add 1 to it then go back to the beginning and still have it equaling name + 1. the problem is it keeps putting it back to 0.

To make it easier here is the part I am talking about.

```
int main()
{
    int w = 0;
    int choice;

    cout << "1: Register\n2: Login\nYour Choice:"; cin >> choice;

    if (choice == 1)
    {
        string username, password;
        cout << "Select A Username: "; cin >> username;
        cout << "Select A Password: "; cin >> password;

        ofstream file;
        file.open("data\\" + username + ".txt");
        file << username << endl << password;
        file.close();

        main();
    }
    else if (choice == 2)
    {
        bool status = IsLoggedIn();

        if (!status)
        {
            int w = w + 1;
            cout << "Unsuccesfull Login!" << endl;
            system("PAUSE");

            if (w == 3)
            {
                return 0;
            }
            else if (w == 2)
            {
                main();
            }
            else if (w == 1)
            {
                main();
            }
            else if (w == 0)
            {
                main();
            }
        }
        else
        {
            cout << "Succesfully Logged In!" << endl;
            system("PAUSE");
            return true;
        }
    }
}`

```

Answer: 
As you do not receive an error of redeclaring the variable `name` it seems like you use your `int name = name + 1;` somewhere in the code when it not see the first declaration. Here the problem is that `int name = name + 1;` second "name" is not declared before and you try to initialize your first "name" with it. 
From start is a a bad approach but here the problem is that when you declare `int name = name + 1;` it is not in the scope of `int name = 0`.

So first be sure you are incrementing your `name` in a place where the compiler "sees" the declaration of `int name = 0` and get rid of the type in `int name = name + 1;`
You are declaring the variable twice. I'd suggest:

```
int name = 0;

```

then later on in the code,

```
name++;

```

You can use also: `++name;` or `name += 1`