Factorial loop that multiplies by previous factorials

The code works, it compiles and works, at least for the first factorial. Then, since I have it in a loop it repeats, but the factorial that is outputted is multiplied by the previous factorial. I don't know what I'm doing wrong and it would greatly help me if someone told me, or at least pointed me towards the right direction.
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
26
27
28
29
30
31
#include <iostream>
using namespace std;

int main()
{
	 int n; //Input #
	int f = 1; //output #
	int m; //Controlls factoring 
	char choose; //prompt repeat

	do
	{
		
		//input #
		cout << "Enter a number greater than or equal to 0: ";
		cin >> n;
		//Mumtiplyer is one, as long as m is less
		//than or equal to one it will continue to grow
		// f (old m) will be multiplyed by new m
		for (m = 1; m <= n; ++m)
		{
			f *= m;
		}
		cout << "Factorial of " << n << " is " << f << endl;

		cout << "" << endl;
		cout << "Find factorial of more numbers? y/n" << endl;
		cin >> choose;
	} while (choose == 'y');
	return 0;
}
you forgot to reset it to 1 after they decided to go again.
move f=1 inside loop.
Last edited on
Thank you so much!!
Topic archived. No new replies allowed.