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

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))
Next


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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.