counts how many times the do while loop occurs

is there any way to count how many times the do while loop occurred for example:
a = 4
b = 7
i know i should return as 2 but im not quite sure on how to implement it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int a;
 int b;
 cin >> a >> b;

 do
 {
        a*=3;
        b*=2;
 } while (a<=b);


 return 0;
}
How about:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int a;
 int b;
 cin >> a >> b;

 int count = 0;
 do
 {
        ++count;
        a*=3;
        b*=2;
 } while (a<=b);

 std::cout << "Loop ran " << count << " times." << std::endl;

 return 0;
}


I kept your code intact and added lines 11, 14 and 19.
Hello paper01,

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
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int a;
 int b;
 int loopCount{};
 
 // <--- Needs a prompt. Unless you like looking at a blank screen.
 cin >> a >> b;

 do
 {
        a*=3;
        b*=2;
        
        loopCount++;
 } while (a<=b);

std::cout << "\n loopCount = " << loopCount << '\n';

 return 0;
}
Thanks you all it really helped alot :)
Topic archived. No new replies allowed.