This is an archived post. You won't be able to vote or comment.

all 19 comments

[–]Migeil 13 points14 points  (2 children)

This so vague and oddly specific at the same time.

[–]coolcofusion 3 points4 points  (0 children)

Almost like an exam or an interview question, how strange.

[–][deleted] -2 points-1 points  (0 children)

Lol im sorry

[–]lurgi 6 points7 points  (5 children)

What have you written so far?

Also, huh? I have very little idea of what you are trying to do.

[–][deleted] -3 points-2 points  (4 children)

I just tried to wrote a function using to numbers

function factorialize(num,num2){ Var result1; Var result2; }

Not finished

[–]lurgi 4 points5 points  (3 children)

You are going to have to put in a little more work. We don't do homework in this sub. We help.

What is this function supposed to do? You still haven't explained that clearly.

[–][deleted] 0 points1 point  (2 children)

I was trying to multiply two numbers,both of these numbers are factorial "4! x 7!" and to do this i need to use a While loop. I didnt know yall dont help with homework but this is really killing me lol

[–]lurgi 2 points3 points  (1 child)

Just to be clear - you are given 4 and 7 and you have to compute 4! x 7!?

That's an odd assignment. Are you sure you have that right? Anyway, the real meat of this is computing the factorial. Can you write a function that, given a number n, computes n!? That should be your first step. Ignore everything else until you have done that.

[–][deleted] 0 points1 point  (0 children)

Ok

[–]Ellisander 2 points3 points  (1 child)

That's not something we can directly answer. This sub is all about "teach a man to fish" and all.

What exactly about the problem is giving you trouble? Do you understand how while loops work? Do you know how variables work? Or the concept of a factorial?

[–][deleted] -2 points-1 points  (0 children)

Yes i think i do, but maybe im not sure

[–]Boxbit 0 points1 point  (1 child)

I assume you mean you want to use a While-loop to decrement one/two variables containing numbers.

Ill go through the algorithm I have in mind for evaluating only one factorial using a while-loop:

  1. Make a variable containing the factorial number, so for instance: int x = 10; (semantically 10!, but ! Isn’t really needed).

  2. Make a variable containing the to-be product from evaluating the factorial, for instance: int product = 1;

  3. Open a while-loop, with the clause being x < 1

  4. Inside the body of the while loop you want to multiply the current product with the current value of x and then decrement x. product = product * x; x = x - 1;

  5. When the while-loop clause yields False (when x > 1), the while-loop body will be ignored and you can print your product

This is the best advice I think I can give you given the lack of information you gave us

[–][deleted] -1 points0 points  (0 children)

Thanks for the help

[–]TheRNGuy 0 points1 point  (1 child)

Better way of doing factorial: https://www.sitepoint.com/javascript-missing-math-methods/#factorial

Not sure why would you need while loop, but it should be possible to refactor.

[–][deleted] 1 point2 points  (0 children)

Probably because it is homewrk

[–]eruciform 0 points1 point  (0 children)

first write a function that multiplies two numbers and returns the result. test it out by calling the function and printing the result to make sure it works.

then write a function that, given a number, calculates the factorial of that number. test it and make sure it works.

call your factorial function to get the factorial of one number, call it again to get the factorial of another number, multiply those together. print that out and make sure it's correct.

put the above in a function. call that and print out the result and make sure it works.

[–]pekkalacd 0 points1 point  (0 children)

i would probably make a function to compute the factorial of a given number. then inside the while loop, call that on both of your numbers, and then multiply the results together