Help with finding a factorial in loops

HI everyone,
so im tasked with making a loop to find the factorial of a number that you enter.But i cannot figureout how to make the factorial part work. For example if i enter the numPlease do not use the word "help".
Content ber 5, it should output 120, but for me it does not. Any tips apprectiated .


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  #include <iostream>
using namespace std;
int main()
{
	int factorial = 1;
	int num;
	

	cout << "Enter a positive number, -9999 to quit :\n";
	cin >> num;
	while (num!=-9999)
	{
		factorial = factorial*num;
		num--;
		cout << "the factorial is" << factorial << endl;
		
	
		cout << "enter another positive number, -9999 to quit" << endl;
		cin >> num;
	}
	cout << "goodbye" << endl;
	
	return 0;
}
	
That's because your loop only iterates once for every number you input.

Use a for loop to calculate the factorial.
Topic archived. No new replies allowed.