Computer Science Canada Factorial Calculator, formula help :? |
Author: | scorpia95 [ Sun Feb 01, 2015 11:00 pm ] |
Post subject: | Factorial Calculator, formula help :? |
There is no textbox to input a number, its supposed to start from 1 when you click "Next" When I click "Next" on my calculator, it's supposed to say 1, and the factorial of 1. Then if I click the button again, it's supposed to say 2 and the factorial of 2. If I click next again its supposed to say 3 and the factorial of 3 and so on... I don't understand how Its supposed to switch over to the next number when I click the button "Next". |
Author: | Insectoid [ Mon Feb 02, 2015 12:13 am ] |
Post subject: | RE:Factorial Calculator, formula help :? |
You can use a textbox that is does not accept input and is not editable by the user. The 'next' button should edit the text in that box, using the built-in textbox properties. |
Author: | scorpia95 [ Mon Feb 02, 2015 12:32 am ] |
Post subject: | Re: RE:Factorial Calculator, formula help :? |
Insectoid @ Mon Feb 02, 2015 12:13 am wrote: You can use a textbox that is does not accept input and is not editable by the user. The 'next' button should edit the text in that box, using the built-in textbox properties.
Cant, we were told that both the number and the factorial box are labels Im supposed to be making something like this http://oi58.tinypic.com/2dpggj.jpg |
Author: | Nathan4102 [ Mon Feb 02, 2015 7:55 am ] |
Post subject: | RE:Factorial Calculator, formula help :? |
In the buttonPressed event of your "Next" button, you could increment a variable by 1, set the number label to your variable, and set the factorial box to the factorial of your variable. |
Author: | scorpia95 [ Mon Feb 02, 2015 12:12 pm ] |
Post subject: | Re: Factorial Calculator, formula help :? |
ty, i figured it out. Now Im stuck at my formula ![]() Formula: N! = (1^2)*(2^2)*(3^2)...*(N^2) Im doing this x = x + 1 N.Text = x For i = 1 To x y = i^2 <-- my "i" isn't squaring all the values from 1 to x, its just squaring "i" at the current "x" NFact.Text = CStr(y) Next |
Author: | Insectoid [ Mon Feb 02, 2015 12:25 pm ] |
Post subject: | RE:Factorial Calculator, formula help :? |
Your first problem is that your formula is wrong. Factorials are defined as N! = 1*2*3*4....*n, which is a lot simpler than what you came up with. Because you only have to compute the 'next' factorial and not a random one, this is really easy. You won't need any loops. You start at 1. when you click 'next' you want to calculate fac(2), which is 1*2. Clicking 'next' again, you want fac(3), which is 1*2*3. But you don't need to calculate all that, because you already calculated 1*2 in the previous step. Find a way to use this to your advantage. EDIT: I see now that you're required to use the more complicated formula. Fortunately, that doesn't matter and the advice I gave you will work the same way. |