help tracing a program

Hello, i would like to know how this program is being trace step by step.

i know the first thing that will be print is

output

first 3 5
second after that i am lost on what to do

#include <iostream>
using namespace std;
int main()
{
int e = 3, f = 5;

cout << "first: " << e
<< " " << f << endl;

while (e <= 4) {
e = f + 1;
f = e + 2;
if (e <= 5)
f = f + 10;
else
e = e - 2;
cout << "second: " << e
<< " " << f << endl;
cout << "enter the next 2 values" << endl;
cin >> e;
cin >> f;
cout << "third: " << e
<< " " << f << endl;
}

cout << "fourth: " << e
<< " " << f << endl;
return 0;
}
Write down the values of e and f after each line.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;
 
int main()
{
   int e = 3, f = 5;

   cout << "first: " << e
        << " " << f << endl;

   while (e <= 4) {//3 < 4 so the loop is entered
      e = f + 1;// e = 5+1 = 6
      f = e + 2;// f = 6+2 = 8 
      if (e <= 5)//6 is not <= 5
         f = f + 10;
      else//,thus
         e = e - 2; //e = 6-2=4
      cout << "second: " << e//4
           << " " << f << endl;//8
      cout << "enter the next 2 values" << endl;
      cin >> e;
      cin >> f;
      cout << "third: " << e
           << " " << f << endl;
   }

   cout << "fourth: " << e
        << " " << f << endl;
   return 0;
}

Try writing down the other cycles on your own.
Topic archived. No new replies allowed.