Recent Forum Posts
From categories:

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
sinx:=xrad
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

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 Tim-Liu Tim-Liu , 18 Dec 2008 14:58

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 Tim-Liu Tim-Liu , 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 Tim-Liu Tim-Liu , 18 Dec 2008 14:55

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

helper~~ XD by Tim-Liu Tim-Liu , 18 Dec 2008 14:53
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License