+ 1

factorial

why it's not give a right outbut when i inbut both negative value or zero #include<iostream> using namespace std; int main(){ cout <<"please enter a postive number to calculate the factorial of it\n"; int fact,x; cin>>x; fact=x; if(x>1){ while(x>1) { x--; fact=fact*x; } cout<<"the factorial value is "<<fact<<"\n";} else if (x=1||x=0) cout<<"the factorial value is 1\n"; else cout<<"please enter a postive number only"; return 0; }

21st Aug 2019, 5:31 AM
Mahmoud Hamed
Mahmoud Hamed - avatar
4 ответов
+ 1
Yes. It is
21st Aug 2019, 5:51 AM
Izzatullo Kanoatov
Izzatullo Kanoatov - avatar
0
Hi bro. I have fixed all the bugs, now it is working like a charm. If you have any questions regarding the code,feel free to keep in touch with me. #include<iostream> using namespace std; int main(){ cout <<"please enter a postive number to calculate the factorial of it\n"; int fact=1,x; cin>>x; fact=x; if(x>1){ while(x>1) { x--; fact=fact*x; } cout<<"the factorial value is "<<fact<<";\n"; } else if (x==1 || x==0) cout<<"the factorial value is 1\n"; else cout<<"please enter a postive number only"; return 0; }
21st Aug 2019, 5:31 AM
Izzatullo Kanoatov
Izzatullo Kanoatov - avatar
0
This is the answer based on your previous question which i think delete alreade. However, it is working ,now you can change some other parts and practise. Have a fun. :-)))
21st Aug 2019, 5:34 AM
Izzatullo Kanoatov
Izzatullo Kanoatov - avatar
0
thank you and this is the final correct code #include<iostream> using namespace std; int main(){ cout <<"please enter a postive number to calculate the factorial of it\n"; int fact,x; cin>>x; fact=x; if(x>1){ while(x>1) { x--; fact=fact*x; } cout<<"the factorial value is "<<fact<<"\n";} else if (x==1||x==0) cout<<"the factorial value is 1\n"; else cout<<"please enter a postive number only"; return 0; }
21st Aug 2019, 5:50 AM
Mahmoud Hamed
Mahmoud Hamed - avatar