CPSC Programe

profileMalikbinn
prog3.pdf

Computer Science 121 – Fall 2016 Program #3 – Due Tuesday, 9/13 by 11:50 am on Titanium (also submit printout) Write a C++ program that will use loops to perform each of the following tasks:

1. Ask the user for two characters from the keyboard and read them into char variables.

Determine which input is larger and which is smaller. Write out all of the characters between smaller and larger including both

end points (the input characters) in small to large order. Example: input of (d k), output of (d e f g h i j k) Example: input of (R M), output of (M N O P Q R)

2. Ask the user for two integer values and read them into int variables. Determine the larger and smaller integers. Write out every second integer, starting with the larger one and stopping at

the lower one. (note: if one number is even and one is odd, the lower value will not show up in the output).

Example: input of (13 5), output of (13 11 9 7 5) Example: input of (13 6), output of (13 11 9 7)

3. Ask the user for an integer in the range of 1 to 10, and read the value into an int variable.

Use a loop to check if the user’s input was in the correct range. If the input value was not in the 1-10 range, write out an error message,

prompt the user for a new value, and read in this new value. Repeat this process until a value in the correct range is found.

Use another loop to calculate the factorial of the input value. (factorial can be found by multiplying together all of the integers from 1 up to your

number, so 4! can be calculated as 1*2*3*4 in a simple counting loop) Output the input value and the calculated factorial value with a text message (i.e. “4! is 24”)

4. Ask the user if they would like to repeat the program (all of the preceding steps (steps 1-3) and read in their response.

If the user chooses to repeat, then repeat steps 1-4 If the user chooses not to repeat, write out a goodbye message and let the

program end. Required Comments: Name block (your name, course number, assignment number) After the name block: A simple description of what the program does. Before each main task, briefly state what that section of code is for When done: Print out and submit your code. Also submit the .cpp file on Titanium.