i started using c++ a few weeks ago , and i was told to build a program the finds the factorial of a number ...

#include <iostream>
using namespace std;
void main()
{
	int x,fact;
	cout<<"Enter the number wanted";
	cin>>x;
	for (fact=1; fact<=x ; fact++);
	{
                        fact = fact * x;
		cout<<"The Factorial ="<<fact<<endl;
		cout<<endl;
	}
}

i dont know what the problem is though

Recommended Answers

All 2 Replies

You cannot use fact as an loop iterator and as your final variable!
Try to see how the program is going to run for x = 3, for example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.