Answer to Question #268122 in C++ for Wendy

Question #268122

Create C++ full program that calculates a factorial (!) of any number between 3 and 9; the

program should give feedback to the user if the number is less than 3(error number is less than3), the program should also give feedback if the number is greater than 9; you can use either the

case or else statement also while loop if applicable


1
Expert's answer
2021-11-18T06:56:39-0500
#include <iostream>
using namespace std;
void factorial(int x){
    if(x < 3){
        cout<<"error number is less than 3\n";
        return;
    }
    if(x > 9){
        cout<<"error number is greater than 9\n";
        return;
    }
    int result = 1;
    int i = 1;
    while(i <= x){
        result *= i;
        i++;
    }
    cout<<"Factorial of "<<x<<" is "<<result<<endl;
}
int main(){
    int number;
    cout<<"Input number: ";
    cin>>number;


    factorial(number);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS