Debug help for this simple short code?

Why is there a difference in output of these two same functions. If you test out factorial(3) and two(3); the factorial gives out list where as two gives out just the number which i want!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  void factorial(int num){
	cout<<"The factorial of "<<num<<" is "; 
	int accumulator=1;
	for(; num>0; accumulator*=num--){
 		cout<<accumulator<<endl;
	}

}
void two(int number){
 
cout << "The factorial of " << number << " is ";
int accumulator = 1;
 for (; number > 0; accumulator *= number --);
 	cout << accumulator << ".\n";
}
Last edited on
Line 13. See that ; at the end? That's the end of the for loop. So line 14 isn't part of the for loop, whereas line 5 is part of a for loop.
@Moschops Ohhh! This is a good trick. Thank You!
Last edited on
Topic archived. No new replies allowed.