I made an application that could check integers between two values (by using spinedits) and then sum the total and display it on a richedit.

This is my code:

var   iAnswer, iBase: Integer;
       iBase := 0;
      for iAnswer := SpinEdit1.Value to SpinEdit2.Value do
       if ((iAnswer mod 2) = 0) then Inc(iBase, iAnswer);
       RichEdit1.Lines.Add('The sum of all the numbers is ' + IntToStr(iBase));

It works great, except I want it to show me the even numbers and then the total e.g If I use 1 to 4, it must show: 2 + 4 = 6

Is this possible?
Thanks for your help :)


Start with an empty string. Each time you Inc() add your number to that string with a plus sign. At the end add the equal sign and the result.

Thanks for the advice, it would have worked well, but I only Inc() once. My empty string is iBase. How would I go about adding a '+' plus each even integer and in the end an equal sign and the the answer? Thanks for your trouble

What have you got/tried so far ?

Thanks, got it working...

Consider marking this thread as solved, and posting your solution to help others.