This output makes no sense in my program
-
I'm doing a program that computes the sum and product of the integers from 1 to 5. Weird thing is when I run the program I get the correct answer for the sum. The sum says 15. Correct. But I get the wrong answer for product. I get 6. I cannot figure out where I'm going wrong:
// This program computes the sum and product of the integers from 1 to 5
program SumAndProduct;
uses
System.SysUtils;var
i : integer;
sum : integer;
product : integer;begin
sum := 0;
product := 1;begin
for i := 1 to 5 do
sum := sum + i;
product := product * i;
end;WriteLn('The sum is ' + IntToStr(sum));
WriteLn('The product is ' + IntToStr(product));WriteLn;
WriteLn('Press Enter to quit...');
ReadLn;
end. -
I'm doing a program that computes the sum and product of the integers from 1 to 5. Weird thing is when I run the program I get the correct answer for the sum. The sum says 15. Correct. But I get the wrong answer for product. I get 6. I cannot figure out where I'm going wrong:
// This program computes the sum and product of the integers from 1 to 5
program SumAndProduct;
uses
System.SysUtils;var
i : integer;
sum : integer;
product : integer;begin
sum := 0;
product := 1;begin
for i := 1 to 5 do
sum := sum + i;
product := product * i;
end;WriteLn('The sum is ' + IntToStr(sum));
WriteLn('The product is ' + IntToStr(product));WriteLn;
WriteLn('Press Enter to quit...');
ReadLn;
end.When I comment out the sum := sum + i line then my program does say product is 120. I'm still trying to figure this out though. Okay I figured it out. I needed to include another begin and end. I guess those are like nested parentheses.