Good afternoon ladies and gentlemen. I'm reviewing Loops from my textbook and a section review question asks what the output should be for the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
using namespace std;
int main()
{
int funny = 1, serious = 0, count = 0, limit = 4;
do
{
funny++;
serious += 2;
}while (count++ < limit);
cout << funny << " " << serious << " " << count << endl;
return 0;
}
|
The output is 6 10 5
This is what I think is happening:
iteration...funny...serious...count
0..............2..........2.............0
1st...........3..........4.............1
2nd..........4..........6.............2
3rd...........5..........8.............3
4th...........6..........10...........4
Given the while condition, how did 'funny' and 'serious' output their values up to the 4th iteration. I thought their outputs would be at 3rd iteration. And more confusing to me, how did 'count' increment all the way to 5 (skipping 4).
Please advise. Thanks in advnace...