Factorial Calculator – WSQ09

Factorial Calculator – WSQ09

This program asks the user for a number and prints the factorial result. It uses a function in which, as long as the variable a is a positive number, then it does the product of b (which has the value of 1) and a (given by the user), using a loop to stop the program when a is equal to itself.

The purpose of the if – else conditional is to make sure, once again, the user is giving the program a positive integer, if the number inserted is lower than 0, the program will ask the user to try again with a positive integer.

To asure this program keeps running while the user wants it to, we use another loop, defining the value for as the character (‘y’), so after it prints the answer it also asks the user if they’d like to try another number, the program will only do the loop if the user answers with y.

Github code link.

Factorial Calculator – WSQ09

CC BY 4.0 Factorial Calculator – WSQ09 by tywins is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.