Apr 30, 2019 at 1:00pm UTC
Do you want the value of multiply to be 99, 100, or 125 after the for loop?
Something along the lines of ...
1 2 3 4 5 6
//do loop execution
do {
cout << "Multiply= " << multiply<< endl;
multiply = multiply * 5;
} while (multiply < 100);
or
1 2 3 4 5 6 7
//do loop execution
do {
cout << "Multiply= " << multiply<< endl;
multiply = multiply * 5;
if (multiply > 100)
multiply = 100;
} while (multiply < 100);
Last edited on Apr 30, 2019 at 2:34pm UTC
Apr 30, 2019 at 5:05pm UTC
I just want the final output to be less than 100.
the user can input any number and it will keep multiplying until the final output is less than 100.
Apr 30, 2019 at 7:22pm UTC
and does the top version of Ganado's code not do that for you?
May 1, 2019 at 2:00am UTC
You could simply not print anything if the loop is at termination condition. This, I think, is the most likely meaning:
1 2 3 4 5 6 7
do {
multiply = multiply * 5;
if (multiply < 100)
{
cout << "Multiply= " << multiply << endl;
}
} while (multiply < 100);
You should note that
Ganado ’s code modifies the behavior of your loop. He is usually more careful than that; perhaps he was tired when he posted.
In any case, part of learning to program is using the most appropriate construct. I would have written:
1 2 3 4
while ((multiply *= 5) < 100)
{
cout << "Multiply= " << multiply << endl;
}
There are other ways as well. Hope this helps.
Last edited on May 1, 2019 at 2:00am UTC
May 1, 2019 at 12:16pm UTC
@jonnin I overlooked it and it does do that.
I didn't know having the formula before the output line would make such a huge difference.
Last edited on May 1, 2019 at 12:19pm UTC
May 1, 2019 at 12:18pm UTC
@Ganado thanks
@Duthomas thanks too. How will Ganado code modify the loop?
May 1, 2019 at 12:40pm UTC
I thought it was about the actual result of multiply and not just what was printed. Yeah I wasn't sure, glad you also responded Duthomhas.