C++ examples for Operator:Arithmetic Operator
A short demonstration of +, -, * and /
#include <iostream> #include <stdlib.h> using namespace std; int main(int argc, char *argv []) { /*from w w w. j a v a2 s .co m*/ int anInt, anotherInt; // Prompt the user for an integer. cout << "Please ty pe an integer and then press Enter: "; cin >> anInt; cout << "Please ty pe another integer and then press Enter: "; cin >> anotherInt; cout << anInt << " + " << anotherInt << " = "; cout << anInt + anotherInt << endl; cout << anInt << " - " << anotherInt << " = "; cout << anInt - anotherInt << endl; cout << anInt << " * " << anotherInt << " = "; cout << anInt * anotherInt << endl; cout << anInt << " / " << anotherInt << " = "; cout << anInt / anotherInt << endl; float aFloat, anotherFloat; cout << "Please enter a floating-point number"; cout << " and then press Enter: "; cin >> aFloat; cout << "Please ty pe another floating-point number"; cout << " and then press Enter: "; cin >> anotherFloat; cout << aFloat << " + " << anotherFloat << " = "; cout << aFloat + anotherFloat << endl; cout << aFloat << " - " << anotherFloat << " = "; cout << aFloat - anotherFloat << endl; cout << aFloat << " * " << anotherFloat << " = "; cout << aFloat * anotherFloat << endl; cout << aFloat << " / " << anotherFloat << " = "; cout << aFloat / anotherFloat << endl; return 0; }