Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will calculate the factorial of number. Example: the factor

ID: 3625274 • Letter: W

Question

Write a program that will calculate the factorial of number.
Example: the factorial of 5 is 5 * 4 * 3 * 2 * 1 = 120
Input the starting number in main() Pass the number to a function called factorial() to calculate the Factorial number
Prototype: double factorial (double num);
In the function: Use a for loop to calculate the answer Use a return statement to return the answer back to the caller.
Back in main, ask the user if they want to another enter number. (Use a loop in main())
Create a function called yesno() Prototype: int yesno(); yesno() should have a while loop in it. Keep looping until they enter y, Y, n, or N. If the user enters y, or Y return 1. If the user enters n or N return 0. Call this function when you need a yes or a no response.
Example of using yesno() from main()
do {
// lots of code
} while (yesno() = = 1);

Explanation / Answer

#include <iostream>

using namespace std;

int yesno() {

bool stop = false;

char input;

while(!stop) {

cin >> input;

if(input == 'y' || input == 'Y' || input == 'n' || input == 'N') {

stop = true;

}

}

if(input == 'y' || input == 'Y') {

  return 1;

}

else {

return 0;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote