Sample C++ code to Subtract Numbers

This post presents a sample C++ Project with which you can learn how to Subtract Numbers in C++ and display the result. The Sample Project provided in this post uses three integer variables to carry out calculations. All the variables are named properly so that you can easily and quickly understand how you can use operators in C++. Given below is the screenshot of a the project described in this project.

Sample Code to Substract Numbers in C++

Sample Code to Substract Numbers in C++

Have a close look at the above provided C++ Sample Source Code. You can also download the C++ file to save you time writing the code or you can also copy paste the code provided in this post. The output of the C++ program is displayed below in a command prompt window. The Author of this C++ Tutorial pressed Ctrl + F5 to build and run the sample project.

Output of C++ Sample Project to Substract Numbers

Output of C++ Sample Project to Substract Numbers

The method used to handle subtract numbers in C++ is similar to the method used in another tutorial in which C++ Sample Code was presented to Add Numbers in C++. This website provides lots of ways and sample C++ programs to let you learn C++ as fast as possible. The given below code of the application can be used in any of your C++ Projects. Do make sure that you do understand how the C++ Program is working and subtracting the numbers.

#include "stdafx.h"#include <iostream>int _tmain(int argc, _TCHAR* argv[]){int iBigNumber,iSmallerNumber;int iResult;iBigNumber = 10000;iSmallerNumber = 789;//First way of Substracting Numbers in C++iResult = iBigNumber - iSmallerNumber;std::cout << "Result of iBigNumber - iSmallerNumber is " << iResult << "n";//Another Example to Substract Numbers in C++iResult = iSmallerNumber - iBigNumber;std::cout << "Result of iSmallerNumber - iBigNumber is " << iResult << "n";return 0;}