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");
}
|