Click here to Skip to main content
15,911,762 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I wanted to ask why my code will run with no errors but it wont give me a value either. Should i have a variable called total incase facNums value is being reset? what it needs to do is multiply each number until the loop hits the number put in so if 5 is put in the textbox it will go 1*2*3*4*5 and outputs the sum. Thanks guys


Java
public void facbutton(eventhandler) {
    facnum = (Int.parseInt(string.valueOf(answerBox.getText())));
    if (facNum < 1) {
        MessageBox mb = new MessageBox (fr, "Facorial Error", "Cannot find the factorial of numbers less than 1.");
        mb.show();
    }
    else 
    {
        for (int i=(FacNum -1); i > 1; --i)
            FacNum *= i;
        answerBox.setText(string.valueOf(FacNum()));
Posted
Updated 18-Jan-13 23:33pm
v2
Comments
Hemant Singh Rautela 19-Jan-13 0:23am    
Just Check using breakpoints or step by step debugging.

You didn't explanin what are these terms
facnum , FacNum , FacNum()

you getting value in facnum and in for loop you used FacNum both are different variable. And Also what about FacNum()

1 solution

You refer to three variables facnum, facNum and FacNum, none of which is defined in the code you have shown. Little wonder that nothing works.


[edit]
And you have a call to a function FacNum()!

I find it hard to believe that this even compiled, so I don't know how you are managing to run it.
[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900