Assignment:
Part 1: Write a program that requires the user to input a non-negative number and then calculates the factorial of that number and prints the result to the screen. Use a while loop to continuously ask for a number (see example output below). If a negative number other than -1 is entered, print and error message and prompt for another input from the user. If -1 is entered, exit the program.
Part 2: Modify your program (in a different file) using switch to print a menu to the screen, asking the user whether they want to calculate the factorial of a non-negative number, or exit. If they choose to calculate the factorial and enter any negative number, print an error message and take them back to the main menu. If they choose an invalid menu option, print an error message and re-print the menu.
I'm having trouble figuring out how to have the computer calculate a number's factorial and then display it. Also after you enter a negative number I don't know how to return back to the while loop so it asks for another number. Any suggestions? Here's what I got so far:
Code:
#include <stdio.h>
int main() {
int big, num;
num = 5;
while (num >= 0) {
printf("Enter the number.\n");
scanf("%d", &big);
num=big;
printf("%d!\n", big);
}
printf("ERROR - You have just entered a negative number, please enter a non-negative number.\n");
}