I was given an assignment that asked this "Write a program that accepts a positive integer between 2 to 15, and then using the number, calculate its factorial (n!). Using do-while statement, make sure it only accepts a valid number (between 2 and 15) – if an invalid number is entered, program should display the original instruction again.
Hint: all variables should be integer
Hint: After do-while loop for input, use for-loop to get the factorial
*** Sample output
Enter a number between 2 and 30: 15
Factorial of 15 is 2004310016."
Well I got most of the code but all i need to figure out is how to use the do-while statement, and make sure it only accepts a valid number (between 2 and 15) – if an invalid number is entered, program should display the original instruction again. Could some one help me please. I'm a noob to this coding and Im struggling . This is my code :
#include <iostream>
using namespace std;
int main () {
int number;
int factor = 1;
do
{ cout << "Enter a number between 2 and 30 : " << endl;
cin >> number ;
for (int i=1; i<= number; i++)
factor *= i; cout << "Factorial of " << number << " is " << factor << endl;
}
while (number =<2 && number => 30);