Recent Forum Posts
 From categories: All categories Variables: Variable Discussion Mathematical Operators: Mathematical Operators Discussion Input: Input Discussion Output: Output Discussion For Loops: For Loop Discussion If Statements: If Statement Discussion Loop Statements: Loop Statement Discussion

Edit: Never mind, found the problem

I've been trying to make a program which will calculate the factorial of a certain number, then the number will change (+2) and it will calculate the factorial again. (This is part of the sine function)

This is the current program, but the output is merely 1. (The expected output is 1,6,120,5040…)

Edit: The new method

var icounter, ifactorial, iexponent : int

iexponent:=1
ifactorial:=1
loop
exit when ifactorial>1000000
icounter := 0
ifactorial := 1
loop
icounter := icounter + 1
ifactorial := ifactorial * icounter
exit when icounter = iexponent
end loop
put ifactorial
iexponent:=iexponent +2
end loop
This seems like it would work, but I'm not sure why it doesn't. Does the nested exit condition cause the entire loop to terminate? The new method works. Final result below

var x, xrad, pi, sinx, flag : real
var icounter, ifactorial, iexponent : int

get x
pi := 3.14159265
xrad := x * pi / 180
iexponent := 3
flag := 1
loop

icounter := 0
ifactorial := 1
loop
icounter := icounter + 1
ifactorial := ifactorial * icounter
exit when icounter = iexponent
end loop

if flag = 1 then
sinx := sinx - (xrad ** iexponent) / ifactorial
flag := 0
else
sinx := sinx + (xrad ** iexponent) / ifactorial
flag := 1
end if
iexponent := iexponent + 2
put sinx
end loop

Nested loop question[Resolved] by , 24 Dec 2008 19:02

yay im the 1st~~ any ways contact me if you have any questions on all the topics on the forum except the if statements as im not quite good at those

helper S2 by , 18 Dec 2008 14:58
18 Dec 2008 14:57
in discussion Variables / Variable Discussion » im da helper :D

yay im the 1st~~ any ways contact me if you have any questions on all the topics on the forum except the if statements as im not quite good at those

im da helper :D by , 18 Dec 2008 14:57

eh.. um.. leave me questions if you want ill try my best to help ya

im still the helper :P by , 18 Dec 2008 14:55
18 Dec 2008 14:53
in discussion For Loops / For Loop Discussion » helper~~ XD

yea since no one is posting here, ill start a thread XD

helper~~ XD by , 18 Dec 2008 14:53