Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / factorialProgram help dbpro

Author
Message
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 14th May 2006 12:06
Hey guys! It's been a while since I last been to these boards, or touched darkBASIC at all for that matter. I am making a program for factorials. (factorial (8!) simply means... 8 * 7 * 6 * 5 * 4 * 3 * 2 *1 which is 40,320. I have written a simple program to calculate factorials. It works good from 0 to 16, but when you input 17, it becomes a negative number (-288522240) and they keep getting negative when you go up in the number input and if you input number is high enough, the answer will be 0. here's my code:

CodemanV
19
Years of Service
User Offline
Joined: 25th Aug 2005
Location: South Wales Valleys, UK
Posted: 14th May 2006 13:45
Hello

When working with a programming language, it is essential that you understand what data types are available and what their limits/ranges are.

You're trying to assign a value to an INTEGER which is higher than what an INTEGER can store. So you need to use a data type which has a larger numerical range than an integer, a DOUBLE INTEGER.

The following snippet loops through numbers 1 to 20 and displays their factorial values stored as an Integer and Double Integer.



Also, have a nose in the DBPro help topic "Main Menu\Principles\Datatypes and variables" as all available DBPro data types and their ranges are explained there.
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 14th May 2006 18:00
Oh yeah. It has been a while since I've been in DB anything and I had forgotten all about that. I remember I used to look through the help files but it was kinda hard for me to understand it until I got a head ache trying to do it then asking for help. Lemme refresh my memorization. Thanks
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th May 2006 07:59
You don't need that IF statement in there.


Login to post a reply

Server time is: 2024-09-24 23:31:12
Your offset time is: 2024-09-24 23:31:12