C++ Programming help

后端 未结 5 513
甜味超标
甜味超标 2021-01-29 06:38

You create a program that displays the sum of even integers between and including two numbers entered by the user ..

ex) 2 and 7 = the sum of 12 (2+4+6)

this is

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-29 07:20

    Your code would end up in an infinite loop.

    Look at the for() loop. You have the condition

    num1 <= (((num2 + 1)/2)*2)
    

    to determine whether your loop terminates. However, since num1 itself is never incremented, and num1 < num2 is guaranteed, this condition will always be true - which means your for loop would never end. I would also suggest using a separate looping variable.

提交回复
热议问题