This task was a little harder, because you had to use more complex logical functions, like a loop, and some other I will explain here.

  • In my code I’m using the variables x , y, and z to operate, being x: the first bound; y: the second; and z: the operator, which is going to sum with x until it reaches y. (Check the code to get it).
  • From line 17 to 21 I use this (below) to handle with the trouble of the user imputing the bounds in the wrong order, being <m> a variable that takes the value of <x> temporally after giving it to <y>.

if (x>y){

m=x;
x=y;
y=m;
}

  • I also use the variables <xx> and <yy>, which are <x> and <y> respectively, so at the end, when you print the result, it prints the original bounds you gave, and not the values they took while doing the operation.
  • If you ask to play again (or try again), you should give back 0 to the values of all the integers, so, if the user tries again, it doesn’t give a wrong sum.

https://github.com/EduardoMacielM/TC1017/blob/master/Sum.cpp

CC BY 4.0 #WSQ07 Sum of Numbers by eduardomacielm is licensed under a Creative Commons Attribution 4.0 International License.