A short demonstration of +, -, * and / - C++ Operator

C++ examples for Operator:Arithmetic Operator

Description

A short demonstration of +, -, * and /

Demo Code

#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; 
}

Result


Related Tutorials