repeating inputs
Sep 3, 2020 at 7:00pm UTC
im having problems where it still considers my last input for example
factorial of 5 = 120
factorial of 6 = 86400 which is 5! x 6!
is there any way is can resolve this
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 32 33 34
#include <iostream>
using namespace std;
int main()
{
unsigned int numb;
unsigned long long fact=1;
do {
//get number
cout << "Enter a number: " ;
cin >> numb;
if (numb == 0) {
cout << "Program terminated"
<< endl;
}
else {
//multiply 1 by
for (int j=numb; j>0; j--)
//numb, numb-1, ..., 2, 1
fact *= j;
cout << "Factorial is "
<< fact
<< endl;
}
} while (numb > 0);
return 0;
}
Sep 3, 2020 at 7:03pm UTC
Move line 8 into the do-while loop's scope.
Sep 3, 2020 at 7:06pm UTC
Thanks it fixed it :)
Topic archived. No new replies allowed.