Computer scienceProgramming languagesC++Operators and expressions

Increment and decrement operators

Up and down

Report a typo

Write a C++ program that takes an integer input from the user and performs the following operations:

  1. Increment the input by 1 and store it in a variable.
  2. Decrement the result from step 1 by 2 and store it in another variable.

Finally, print the values of both variables along with a message indicating the operation performed on each.

Sample Input 1:

3

Sample Output 1:

After incrementing by 1: 4
After decrementing by 2: 2

Sample Input 2:

0

Sample Output 2:

After incrementing by 1: 1
After decrementing by 2: -1
Write a program in C++





Create a free account to access the full topic