Answer to Question #266517 in C++ for Wendy

Question #266517

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 than 3), the program should also give feedback if 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:55:50-0500
#include<iostream>
using namespace std;
int val(int n){
	int r = 0;
		if(n<3){
		cout<<"The number is less than 3\n";
		r = 1;
	}
	else if(n>9){
		cout<<"The number is greater than 9\n";
		r = 1;
	}
	else{
		r = 0;
	}
	return r;
}
int main(){
	cout<<"Enter a number: ";
	int n;
	cin>>n;
	
	if(val(n)==0){
		int fact = 1;
		for(int i=1; i<=n; i++){
			fact *= i;
		}
		cout<<"Factorial of "<<n<<" is "<<fact<<endl;
	}


}

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