factorial | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

factorial

if i want to do sevral calculation without runing the program after each tryv what i have to do ? #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, 10:00 AM
Mahmoud Hamed
Mahmoud Hamed - avatar
3 Answers
+ 2
Mahmoud Hamed it will be like while(opt!=2){ your codes..... cout<<"do you want to continue?"; cin>>opt; }
21st Aug 2019, 10:19 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 2
enclose your code in a do while loop or while loop, and taking a value to quite or continue, e.g while(opt!=2){ your codes....... }
21st Aug 2019, 10:07 AM
✳AsterisK✳
✳AsterisK✳ - avatar
0
do you mean while(opt!=2 ) { my code }
21st Aug 2019, 10:13 AM
Mahmoud Hamed
Mahmoud Hamed - avatar