0

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

Edited by danillp: Code Change

2
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by pritaeas
0

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.

0

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

0

Thanks, got it working...

Edited by danillp: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.