Stuck in a While loop despite it being changed to false?

Just to make sure I understand how it's supposed to be working..
The "while" I made starts if and only if the bool StatsDone equals false.
And it does, since I made that bool false when I created it.
If the "StatsDone" bool I made is later changed to True, once everything inside the While is done it shouldn't do the While again, right?
As you can see, in this code I made it so that if the int "StatVerificationSum" equals 62 it should change the "StatsDone" bool to "true", which means that by the end it shouldn't run the whole "while" again, right?
Well, I make the sum 62, which makes the "if" change StatsDone to true (I used "cout << StatsDone ;" to see that it was changed, and it was, since it gives me a "1"), but after that it goes back up to the "You may assign one of these to each", as if StatsDone were still false.

What am I doing wrong here?
Have any solutions to my problem?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>

using namespace std;

int main()
{
	//Base Stats that will be assigned by Player
	int BaseStr = 0;
	int BaseDex = 0;
	int BaseCon = 0;
	int BaseWis = 0;
	int BaseInt = 0;
	int BaseCha = 0;

               	int StatVerificationSum = 0;

               	bool StatsDone = false;
               	
               	        cout << "Now, to complete character creation you are to assign your base stats.\n";

                    while ( StatsDone == false )
                 	{
               	        cout << "You may assign one of these to each stat: 15, 15, 10, 10, 6, 6\n";
               	        cout << "Which will you assign to Str? ";
               	        cin >> BaseStr;
               	        cout << "Dex? ";
               	        cin >> BaseDex;
              	        cout << "Con? ";
              	        cin >> BaseCon;
              	        cout << "Int? ";
              	        cin >> BaseInt;
              	        cout << "Wis? ";
              	        cin >> BaseWis;
              	        cout << "Cha? ";
              	        cin >> BaseCha;
 
                        //Verifying the numbers have been input correctly             	
                       	int StatVerificationSum = BaseStr + BaseDex + BaseCon + BaseInt + BaseWis + BaseCha;
              	        if (StatVerificationSum == 62)
                        {
                          bool StatsDone = true;
                          cout << "Your totals are blah blah blah blah\n\n";
                          cout << StatsDone ;
                          cout << "\n\n";
                        
                        }
                        else
                        {
                          cout << "\n\nIt seems you haven't assigned your stats correctly. Try again.\n\n";
                        }
                        }
 
 		system("pause");                  
}
On line 41, you're not setting your existing StatsDone variable to true - you're creating a new StatsDone variable that only exists inside the scope of that if block, and which is different from the one you declare on line 17.

What @MikeyBoy said is exactly the problem!
If you want to use that same variable then do not declare it in another scope too, just use the existing name on it's own, with however you want to use it.

In this case you need to change from:
1
2
//41
bool StatsDone = true;

Into this:
1
2
//41
StatsDone = true;
Oh! Of course.
Thanks for helping this newbie out.
Might have been something simple but I really appreciate it.
Last edited on
Topic archived. No new replies allowed.