Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Compute the Factorial of a number Compute the Superfactorial of a number Quit #include using namespace std; void getValidUserInputPosNumGT0 (int *a) // this void will
- Compute the Factorial of a number
- Compute the Superfactorial of a number
- Quit
#includeusing namespace std; void getValidUserInputPosNumGT0 (int *a) // this void will pass by reference and store the value chosen by the user. { int num; cout << "Enter in a positive number greater than 0... "; // This is what will print after the switch is done by the code for what the user chooses. cin >> *a; // the integer number the user chooses to use. } long double factorial (int num) // The factorial while calculate the number chosen. { int fact = 1; while (num > 1) { fact *= num; num--; } return fact; } long double SuperFactorial (int num) { { return (num==1 || num==0) ? 1: num * SuperFactorial(num - 1); } return num; } int main () { int ch; int num; cout << "Welcome to the playing with numbers program! "; do { cout << "1) Compute the factorial of a number "; cout << "2) Compute the SuperFactorial of a number "; cout << "3) Quit "; while (true) { cout << "Select an option (1..3).."; cin >> ch; if (ch == 1 || ch == 2 || ch == 3) { break; } } switch (ch) { case 1: getValidUserInputPosNumGT0(&num); cout << "Factorial("< when I run my code and choose Select an option (1..3)..3 it doesn't work and when I ran my code when I enter zero or a negative number like -9
Enter in a positive number greater than 0...0
SuperFactorial(0)=1
Enter in a positive number greater than 0...-9 Factorial(-9)=1
They still get ran through the code when it should just start back at Enter in a positive number greater than 0... what am I doing wrong?
It should run like this
Welcome to the playing with numbers! 1) Compute the Factorial of a number 2) Computer the SuperFactorial of a number 3) Quit Select an option (1..3)..1 Enter in a positive number greater than 0...0 Enter in a positive number greater than 0...-9 Enter in a positive number greater than 0...2 Factorial(2) = 2 1) Compute the Factorial of a number 2) Computer the SuperFactorial of a number 3) Quit Select an option (1..3)..1 Enter in a positive number greater than 0...3 Factorial(3) = 6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started