Variable stuck in a loop

I want to create a loop that that generates a random number set and gives the user the option to run the loop again for a new number. I have that working but when the loop ends the variable value does not leave the loop. I tried a posttest and pretest loop.
Is it possible to declare/create/alter a variable in a loop and have that value exit the loop to use in the code later?
I am still learning about global variables.

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

int oneDiceSix() // Roll 1d6
{int oneDiceSix = 1+(rand()%6);
return oneDiceSix;} //end function

int main()
{
srand(time(0));

int pcStr = 0;

bool reroll = true;
char redice = 'y';

do //Start Loop
{
int pcStr = oneDiceSix() + oneDiceSix() + oneDiceSix();
cout << "You rolled a " << pcStr << " for your strength." << endl;
cout << "Do you want to reroll this score? " ;
cin >> redice;
if (redice == 'y' || redice == 'Y'){reroll = true;}
else if (redice == 'n' || redice == 'N'){reroll = false;}}

while (reroll == true);

cout << "Your Strength score will be " << pcStr << "." ;

}
I have discovered if I change my variable to g_pcStr the variable can exist outside a block (block scope). I have the code doing what I want now. I am curious if there is a better method and if anyone has some advice. Thank you.
You could use .h files or if you REALLY want to a global variable.
Topic archived. No new replies allowed.