Hi, beginner here.
I have this program where I use rnd.next to generate a random number from 1-14, however this happens inside a while loop, and in this while loop, the same variable is responsible for many calculations and it has to be equal to 0 at a point in order for the while loop to continue (To make this happen, I manually set the variable to = 0). I want to know if I can take the variable's previously randomly generated value and STORE it onto another variable Before it reaches the variable = 0 line :
I tried using if statements like this, but it didn't seem to work, and I tried using else but i kept getting build errors. I'd really appreciate any help as to why what I did doesn't work or if there's any alternative solution, Thanks!
My failed solution below :
I have this program where I use rnd.next to generate a random number from 1-14, however this happens inside a while loop, and in this while loop, the same variable is responsible for many calculations and it has to be equal to 0 at a point in order for the while loop to continue (To make this happen, I manually set the variable to = 0). I want to know if I can take the variable's previously randomly generated value and STORE it onto another variable Before it reaches the variable = 0 line :
C#:
result = (randomlygeneratednumber);
//find a way to store result's value before it is changed
result = 0;
My failed solution below :
C#:
bool Storecheck;
Storecheck = true;
if (Storecheck == true)
{
result = (randomlygeneratednumber);
}
Storecheck = false;
result = 0;
Last edited by a moderator: