cant figure this program out. please help!

Write your question here.
Can't seem to figure out the output of this code. thought it was 14, but it came out 101. Please explain this to me.
1
2
3
4
5
6
7
 int i = 11;
 while (i <= 99)
 {
  i = i + 3;
 }
  cout << i;
  


Here is your code in words:

You start off with i equal to 11.
Your code will run adding 3 to i as long as i is less than or equal to 99
when i is greater than 99 it drops out of loop and outputs result

so what is happening is is your code will continue to add 3 to i until it is greater than 99.

So i starts off at 11 and eventually equals 98, and 98<99 so the code runs 98+3=101. 101 is not less than or equal to 99 so it drops out of the loop and outputs the value of 101.

hope this helps
Topic archived. No new replies allowed.