----------------------------------- riveryu Sat Feb 16, 2008 4:24 pm "Overflow in Integer expression"- how do i fix this? ----------------------------------- I wrote an answer program to a question that says -- user inputs numbers from 1 - 30 , program outputs the factorials( defined 1x2x4x5 .. the number) . I found that when the user enters anything bigger than 12! = 479 001 600 will result in "Overflow in Integer expression" (cuz Turing suckz...). How do i fix this problem? ( I dont need an answer to the question, i need a solution to the integer overflow problem) Maybe my teacher asked too much, since im only supposed to have learned about loops, for, var :int, real, nat, string, cls, put get... etc. No arrays, fcns o proc etc... Anyways, juz letting u know; assuming if this have anything to do with solving the problem. ----------------------------------- Clayton Sat Feb 16, 2008 4:28 pm RE:"Overflow in Integer expression"- how do i fix this? ----------------------------------- The problem is that 13! is greater than 2^31 - 1, which is the upper limit to integers in Turing. If you want anything bigger, you're going to have to start thinking outside the box I'm afraid. ----------------------------------- BigBear Sat Feb 16, 2008 4:29 pm Re: "Overflow in Integer expression"- how do i fix this? ----------------------------------- Well if you post your code we might be able to tell why it is happening. I don't remember even having that error. ----------------------------------- Saad Sat Feb 16, 2008 4:30 pm RE:"Overflow in Integer expression"- how do i fix this? ----------------------------------- You can use real's for 30! since reals have a bigger range, however you will loose precision in the number ----------------------------------- BigBear Sat Feb 16, 2008 4:43 pm Re: "Overflow in Integer expression"- how do i fix this? ----------------------------------- What is the difference ? Reals and every number and Integers and only whole numbers and since he is working with whole number integers should work. ----------------------------------- Clayton Sat Feb 16, 2008 4:59 pm RE:"Overflow in Integer expression"- how do i fix this? ----------------------------------- Try the following two programs: fcn fact (num : int) : real if num 30 for i : 1 .. num cls fac := i * fac % everytime it loops, i is multiplied with the previous result % since i timing 1 is equal to i at first % this is equivalent to i timing it self % everytime the it loops, 1*2*3*4.. number put num, "! = ", fac delay ( 200) % this is here to show u the problem in slow motion, error comes after 9 digits end for fac := 1 %changes fac back to 1 to clear the amount acuminated earlier put "Do you wish to find out more factorials? Y/N" get ans exit when ans = "N" or ans = "n" end loop *cough* Im "beginner" cuz i juz started grade 10 programming for 2 weeks, im not suppose to know about fcns and procs *cough* ----------------------------------- zylum Sat Feb 16, 2008 6:13 pm RE:"Overflow in Integer expression"- how do i fix this? ----------------------------------- why can you only use integers in for loops?? try changing your fac variable to a real.. It wont give you an exact answer but at least it wont crash. ----------------------------------- riveryu Sat Feb 16, 2008 6:46 pm Re: "Overflow in Integer expression"- how do i fix this? ----------------------------------- O, oops...:oops: Thx zylumm, Clayton and Saad, and ppl. I misunderstood something in message the Turing debugger gave me while i was adjusting the program which messed me up... and got the impression that u can't use int for the forloop. Sry Im not sure if this is the place to say this but... Pehaps this problem should be addressed in one of the tutorials, as in the difference of real and int in respect to scientific notation The Turing Walkthrough only mentioned this: Real Numbers: Real numbers can contain decimal places. Turing supports up to 16 decimal places for real numbers. Real numbers contain the realms of the positive, the negative, and zero. Integers: We should all know what an integer is, given some fundamental math. Just to make sure, an integer is a whole number; it has no decimals; it is a fraction whose denominator is 1; it can be negative, zero, or positive. Maybe this is too obvious for some ppl but i dont think it is for beginners who nvr touched a programming language before, espicially for ppl who learn Turing since Ontario (CA) use Turing for all grade 10 - the first standard CS(not Counter Strike) course a student encounters. ----------------------------------- LaZ3R Sun Feb 17, 2008 11:54 am RE:"Overflow in Integer expression"- how do i fix this? ----------------------------------- Real can hold values up to 306 exponents at most, using it for extremely large numbers is your best bet. Though you won't be able to display every digit (without thinking outside the box), you at least won't get an overflow. ----------------------------------- riveryu Sun Feb 17, 2008 1:41 pm Re: "Overflow in Integer expression"- how do i fix this? ----------------------------------- Im not very familiar with the meanig of "outside the box", I think thats sort too broad for some ppl... I played around with Clayton's functions - is this one the things outside that box, ? (look at last line in the code) fcn fact (num : real) : real if num