Q and Attempt included : small Integer * small integer / 100 gives me  16890000

Posted on 2005-03-29
Medium Priority
Last Modified: 2010-04-05
hi, i hope there is something small i miss here.

The Problem:
1) this is a simple mathematical equation which returns me extraordinarily big numbers
2) not major important : i dont know how to add a item to a listbox (im using delphi 5)
i have included my attempts.
i also have a link to a 50k zip file , including a JPG of the assignment.
this is not a homework exercise, i tried for at least a hour and a half and end up with jack.


this is the question:
a small program is writter to determine if groups of animals are becoming
bigger or smaller
this is the formula:
Next Population = Population * Growth Factor / 100

the user interface contains a spinedit : sedGrowthFactor
and a spinedit sedPopulation. when the user enter clikcs on Next
forecast button two things happen. Program calculates predicted number of animals
and displays this in sedPopulation.

thus for e.g. the user enters a growth factor of 120,
and Currentpopulation of 100, and Growth factor of 15 then
it would say:

Iteration 5 Initial = 115  Final = 138
Iteration 6 Initial = 138 Final = 165
Iteration 7 Initial = 165 Final = 198 ( i get 16842838)

My Attempt:
unit A1Q7;


  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ComCtrls, Spin;

  TForm1 = class(TForm)
    bmpResetClick: TBitBtn;
    sedFactor: TSpinEdit;
    sedPopulation: TSpinEdit;
    sedIteration: TSpinEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    btnNextForecast: TButton;
    lstPopulations: TListBox;
    procedure bmpResetClickClick(Sender: TObject);
    procedure btnNextForecastClick(Sender: TObject);
    { Private declarations }
    { Public declarations }

  Form1: TForm1;


{$R *.DFM}

procedure TForm1.bmpResetClickClick(Sender: TObject);
        sedFactor.Value := 100;
        sedPopulation.value := 0;
        sedIteration.value := 0;
        sedPopulation.Enabled := True;

procedure TForm1.btnNextForecastClick(Sender: TObject);
 NextPopulation,Population,GrowthFactor,Iteration : Integer;
 s : string;
 i : integer;
        Iteration := sedIteration.value;
        GrowthFactor := sedFactor.value;

        for  i := 1 to Iteration do
          Population := NextPopulation;
          //NextPopulation := strToInt(FloatToStr((Population * GrowthFactor) / 100));
          //NextPopulation := FloatToInt((Population * GrowthFactor) / 100);
          s := FloatToStr((Population * GrowthFactor) / 100);
          //lstPopulations.additem('Iteration ' + intToStr(i) + ' Initial = ' + intToStr(Population) +  ' Final = ' + inttostr(NextPopulation))

          sedPopulation.value := NextPopulation;
          sedPopulation.Enabled := False;
Question by:jxharding
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Author Comment

ID: 13651672
i also tried :
population := sedPopulation.Value * sedFactor.Value div 100
LVL 11

Accepted Solution

pcsentinel earned 2000 total points
ID: 13651726
I think this is what you want

procedure TForm1.btnNextForecastClick(Sender: TObject);
 GrowthFactor,Iteration : Integer;
 Population: Integer;
 i : integer;
        Iteration := sedIteration.value;
        GrowthFactor := sedFactor.value;
        Population := sedPopulation.value;
        for  i := 1 to Iteration do
           Population:=trunc((Population * GrowthFactor) / 100);
        sedPopulation.value := Population;
        sedPopulation.Enabled := False;


The reason you are getting a strange number in your code is that you are not doing and initial set of NextPopulation so its just picking up any old number. In Delphi you need to set Local variables i.e. NextPopulation:=0; otherwise it will just pick up the number that occupies the memory area already

Hope this helps
LVL 11

Expert Comment

ID: 13651740
Also re adding items to a listbox just use


Author Comment

ID: 13651854
brilliant, thank you so much!!!!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question