Hi,

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;
      begin
       iBase := 0;
      for iAnswer := SpinEdit1.Value to SpinEdit2.Value do
      begin
       if ((iAnswer mod 2) = 0) then Inc(iBase, iAnswer);
      end;
       RichEdit1.Lines.Add('The sum of all the numbers is ' + IntToStr(iBase));
      end;

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 :)

Regards

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.