I am trying to write a c++ program in the most clean way possible. The code snippet looks something like this :
int result = 0;
while ((result = (fullBottles / numExchange)) >= numExchange)
{
ans += result;
fullBottles = result;
}
Although, the above code snippet is still clean. But how can i achieve this ?
while ((int result = (fullBottles / numExchange)) >= numExchange)
{
ans += result;
fullBottles = result;
}
Because I don’t have any use of the variable result after the loop. So, I want it to get destroyed as soon as the loop exists. How can i do that ?