0
I don't know why this c++ factorial code isn't working
#include <iostream> using namespace std; int main() { int n,i; cout<<"Please enter the factorial..."<<endl; cin>>n; i=1; while (i<=n) n=n*i; i++; cout<<"The factorial = "<<n; return 0; }
3 Answers
+ 6
@Mahmoud This is not python , {} is mandatory :D
+ 2
#include <iostream>
using namespace std;
int main()
{
int n,i,fact;
cout<<"Please enter the factorial..."<<endl;
cin>>n;
i=1;
while (i<=n)
{
fact*=i;
i++;
}
cout<<"The factorial = "<<fact;
return 0;
}
Change log
braces after loop
you were updating n itself so the loop had must become endless.