# Simple Calculations

## Program Listing

• This program will perform simple calculations involving ints, floats, and chars.
• Can you explain why '1' + '2' = 'c' ?

### SimpleCalcs.cpp

 ```/************************************************************************ * * * Program: Simple Calcs * * * ************************************************************************/ #include #include using namespace std; int main() { // Do an integer calculation int a; // An integer int b; // Another integer cout << "Enter two integers: " << flush; cin >> a >> b; // Read two integers cout << "The sum is " << a + b << endl; // Print their total // Do a floating-point calculation cout << endl; float x; // A float cout << "Enter a floating-point number: " << flush; cin >> x; // Read a float float recip = 1/x; // Find its reciprocal cout << "The reciprocal is " << recip << endl; // Do a character "calculation" cout << endl; char r = '1'; // The character '1' char s = '2'; // The character '2' char sum = r + s; // Add the chars cout << "The sum of '1' and '2' is " << sum << endl; return 0; }```

### Sample Run

 ```Enter two integers: 4 8 The sum is 12 Enter a floating-point number: 3.2 The reciprocal is 0.3125 The sum of '1' and '2' is c ```