Overview

This lab focuses on integer arithmetic, flow control, and processing user input.

  • Due Thurs 20 Sep 2018 at midnight

  • Use the repl.it C++ template to complete the following.

    • Save your final code as a .cpp file.

  • Collect the the output of the required runs (below) in the editor of your choice (e.g., Office, Google Docs, etc.)

    • Export your document as a pdf (try "Print to PDF")

  • Upload both your code and your pdf here:

Detailed Instructions

Write a C++ program that asks the user for a 4-digit integer, and verifies user input. The program then prints the number in reverse order. The program then asks the user whether to repeat the process, or to quit.

Please note the following:

  • The program must take input as a single integer (not as as a sequence of characters).

    • The program must also return the output as a single integer (not print digit-by-digit).

  • The program should inform the user if the input is not a 4-digit integer. For example, 0345 and 12345 are not 4-digit integers.

  • You may assume that users input a positive integer (as opposed to other kind of data, such as a character).

  • When the last digit (units) of the input is 0, the reverse is not a 4-digit number: in this case, report the reverse as a 3-digit number.

Sample Output

Input a 4 digit Number and press Enter: 452
452 is not a 4-digit number

Input a 4 digit Number and press Enter: 1432
1432 reversed is 2341

Enter Q to quit, or any letter to continue: c

Input a 4 digit Number and press Enter: 4325
4325 reversed is 5234

Enter Q to quit, enter any letter to continue: Q
Thanks for playing!

Hints

  • In the decimal number system, each digit shows the number of a multiple of 10.

    • Ex: 123 = 1*100 + 2*10 * 3*1

  • When all operands are integers, the / operator returns the number of complete divisions (discarding the remainder).

  • The % operator returns the remainder of integer division.

Grading

Requirement Points

Correct output on required trial data

50

Code formatting (indenting, whitespace)

15

Code readability (informative comments & variable names)

15

Program Output Document

20