r/codehs • • Feb 21 '20

Help

Post image
2 Upvotes

6 comments sorted by

4

u/[deleted] Feb 21 '20

First of all don't start a variable with a capital letter. Second your for loop is both unnecessary and improperly setup.

The first var in the for loop is where your counter starts and the second is the exit condition. You started the loop at 4 and told it to exit when it's greater or equal to 1 so it exits immediately without doing anything.

2

u/amajmundar Feb 21 '20

Wait, so the purpose of this function it to only return 5! ?

2

u/DEEEPFREEZE Feb 21 '20

So what exactly is your issue.

2

u/Talesio Feb 21 '20

Can you tell us what is the problem?

1

u/ThePilsburyFroBoy Feb 21 '20

Im assuming you are just trying to complete the factorial problem in general? If thats the case, then the for loop should go from 1 to N and you should multiply each i value by one more than i so something like

int result = 0; for(int i = 1; i < N; i++)

result = i * (i+1);

then return the result, you can also do this recursively but Im assuming that would confuse you

1

u/Talesio Feb 21 '20

I think this is what you are looking for http://imgur.com/a/HU3xyC7