Increment-Decrement a number in C++

Download
Download is available until [expire_date]
  • Version
  • Download 16
  • File Size 1.43 KB
  • File Count 1
  • Create Date April 27, 2016
  • Last Updated April 27, 2016

Increment-Decrement a number in C++

Increment-Decrement a number in C++

Increment means to add or increase, decrement means to deduct or decrease. This c++ program will demonstrate how to increment and decrement a number. The user will be given an option to either increment or decrement a value, then the user will be ask to enter a number, the program will then perform the operation selected by the user.

If you’re using codeblocks, kindly open the incrementdecrement project file, you can also open the main.cpp in codeblocks.
Source code:

#include < iostream >

using namespace std;

int main()
{
    int selection, number;
    cout << "selection: " << endl;
    cout << "enter 1 to increment a number: " << endl;
    cout << "enter 2 to decrement a number: " << endl;
    cin >> selection;
    cout << "enter a number: " << endl;
    cin >> number;
    cout << "------------------" << endl;
    if (selection == 1)
    {
        number++;
        cout << "result: " << number << endl;
    }
    else
    {
        number--;
        cout << "result: " << number << endl;
    }


    return 0;
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.