Structured Programming in C++
Prof. Gregory Safko

Camden County College, Cherry Hill Campus

Lab 2 


1. Arithmetic revisited (arith2.cpp)

Revise your “Arithmetic” program from Lab 1 so that it does not compute or display the divisions and remainder (mod, the % operator) when the second integer entered is zero.

Here is one possible output format, with several example runs:

Please enter an integer: 7
Please enter another integer: 8
7 + 8 is 15
7 - 8 is -1
7 * 8 is 56
7 / 8 (integer division) is 0
7 % 8 is 7
7 / 8 (floating-point division) is 0.875
Press any key to continue


 
 
Please enter an integer: 20
Please enter another integer: 0
20 + 0 is 20
20 - 0 is 20
20 * 0 is 0
Press any key to continue

2. Divisibility testing (divtest.cpp)

Write a program that prompts for an integer, and indicates whether it is even or odd, whether or not it is divisible by 3, and whether or not it is divisible by 4. (Hint: use the % operator. "Even" means "divisible by 2".)

Here is one possible output format, showing two example runs:

Enter an integer: 8
8 is even.
8 is not divisible by 3.
8 is divisible by 4.
Press any key to continue


 
 
Enter an integer: 9
9 is odd.
9 is divisible by 3.
9 is not divisible by 4.
Press any key to continue


 
 
Enter an integer: 10
10 is even.
10 is not divisible by 3.
10 is not divisible by 4.
Press any key to continue