Anonymous asked in Computers & InternetProgramming & Design · 8 years ago

Help with C++ programming?

I need to 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.

Sample of the output would be:

Enter a number between 2 and 30: 15

Factorial of 15 is 2004310016.

I have the basics down ( entering numbers and putting out text and such) just not the actual calculations and such.

1 Answer

  • 8 years ago
    Favorite Answer

    Since you have to use loops, here is the solution for a no. n :

    public int fact(int n){

    int i = n - 1;


    n = n * (i);

    i-- ;


    return n;


Still have questions? Get your answers by asking now.