Menu
Search




Articles & Documents

Close Tutorials

Newsletter
To receive news about this website, consider subscribing to our Newsletter.
Subscribe
Unsubscribe
22 Subscribers
CPDB.Net

Friends News
Visits

   visitors

   visitors online

Webmaster - Infos

Forum - Forum
Pépé le compiler - Pépé le compiler


active  Topic # 44  I was posting in the wrong place

31/12/2011 @ 18:02
by lebill2

lebill2



I posted about the simple calculator in the wrong area. I'm using the Android compiler, so I should have posted here, correct? (I'm using a rooted Coby Kyros Mid7015 with Android 2.1).

Ok, so I started to write the for - to code that didn't work, and realized this was also my mistake: I forgot to put a line saying:

sum:=0;

So the answer was always different. After inclusion of this line everything worked perfectly!

I'm obviously still learning, and making basic mistakes... smile

Anyway, here's the code:

My intention is to sum all even numbers from 1 to 100:

program sum_of_evens;

var cont, sum: integer;

begin
 sum:=0;
  for cont:= 1 to 100 do
  begin
   if cont mod 2 = 0 then
    begin
     sum:=sum+cont;
    end;
  end;

writeln('');
writeln('The sum of all even numbers from 1 to 100 is: ',sum);
readln;

end.

Thanks for the patience!

-Bill
  Post an answer  Top
active topic active   closed topic closed   Sticky Sticky   New New message   -   Correct Correct message   Close Close topic   Make sticky Make sticky
[]
Forum Topic  Forum 




^ Top ^