Question: C Programing Part II Write a program: Ask the user to enter a number between 1 and 20. If they enter a number outside of
C Programing Part II
Write a program:
Ask the user to enter a number between 1 and 20. If they enter a number outside of that range, print an error message, and call the function:
exit(-1); // stop the program immediately with an error code of -1.
Use a switch statement to output the corresponding Roman numeral for the number that they entered. Note that you dont have to do any calculations for this, just a big switch with 20 cases, and a default case for numbers out of range.
Part III
You can generate a random number in C using the following code:
int myRandomNumber;
srand(time(NULL)); // seed the random number generator
myRandomNumber = rand(); // each time you call this function there will be a different random number.
Generate a random number, and output it. Use if statements to determine if the number is odd or even, and output a message to that effect. Similarly, output if the number is divisible by 3, and if it is divisible by 10. Use the % operator to achieve this.
Run the program, and print the results several times using different numbers to be sure that its working.
Hint: In C you can not declare variables after you write executable code. For example if you call the srand function, and then declare some more variables after that call, the program will not compile. The compiler messages are not very helpful. Put all the variable declarations at the top of the function.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
