Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How do i write the pseudo and javascript code for this?

    how do i write a recursive program to calculate the factorial of a number between 0 and 6.if the user enters a number greater than 6 you should prompt the user again to input another number or -1 to exit the program.how do i write the pseudo code and the javascript code for this program?
    i have no idea of how to do this and have been trying to figure it out since the last hour

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    post the code you have so far and we can try to help you get it working. It's fairly straight forward.

  • #3
    Regular Coder Krupski's Avatar
    Join Date
    Dec 2010
    Location
    United States of America
    Posts
    505
    Thanks
    39
    Thanked 47 Times in 46 Posts
    Quote Originally Posted by university View Post
    how do i write a recursive program to calculate the factorial of a number between 0 and 6.if the user enters a number greater than 6 you should prompt the user again to input another number or -1 to exit the program.how do i write the pseudo code and the javascript code for this program?
    i have no idea of how to do this and have been trying to figure it out since the last hour
    Do the pseudo code first. That will make it a lot easier to write the real code in any language you want.

    Pseudo code would be made of words and concepts like this:

    (1) ASK USER FOR NUMBER
    (2) INPUT NUMBER RESULT ---> X
    (3) IS X less than 0?
    (4) YES, PRINT ERROR MESSAGE AND GOTO 1
    (5) IS X greater than 6?
    (6) YES, PRINT ERROR MESSAGE AND GOTO 1
    (7) (comment) if here input is in range.
    (8) ANSWER = 1 (comment) declare a variable
    (9) ANSWER = ANSWER times X
    (10) X = X - 1
    (11) IF X greater than 0 GOTO 9
    (12) PRINT result is ANSWER

    Make sense?
    "Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •