need help with basic program.trying to write a program in qbasic to take in a integer calculate and print out the factorial.been on this for a long time

14 Years
Discussion Span
Last Post by scisoft

could you possibly post the code you have so we can tell exactly what you need help with. that would make it easier to help up thanks :)


I haven't coded in QBasic in years, but in VB it would be like the following:

Dim intNumber As Integer
Dim lngFactorial As Long
Dim lngCounter As Long
intNumber = 5
For lngCounter = 1 To intNumber
  lngFactorial = lngFactorial * lngCounter
Next lngCounter

"lngFactorial" would then be your number. Is this what you're looking for?


If you do not use logarithmus, you will be getting overflow error for factorial of integers larger then approx. 280.
This is VB6 code:
Dim l As Long
Dim res As Double
For l = 1 To total
res = res + Log(CDbl(l))

The final result "res" is used for furhter mathematical operation, rather then directly printing its value val= Exp(res), since if val is too high, you would just get the overflow error.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.