Getting stuck with simple c++ code, explained

Revision en1, by Kaleab_Asfaw, 2020-07-26 12:41:47

I am a beginner in c++, I am trying to write a program that read 7 integers like x, a, b, c, d, e, f.

The program is to count how many of the following condition are true:

x is in [a, b]

x is in [c, d]

x is in [e, f]

so the program will return either 1, 2, 3. my program :

Code:

I used to variable a and b to get input for the three pair intervals.

sample input : 7 1 10 5 6 4 40

expected output: 2

The program final result will give 2, but when I uncomment line 12 (print the value of the a and b before increment cnt ) the final result will be 3.

I don't know why I am getting different result. Does printing have effect of the code below?

I haven't seen this kind of thing in Python3 (know well). This question might seem silly for you but I am very confused why this is happening?

Thanks in Advance!

Tags help, error

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Kaleab_Asfaw 2020-07-26 12:41:47 1318 Initial revision (published)