< Previous | Contents | Next >

Introducing the Expensive Calculator

Program

Most serious computer gamers invest heavily in a bleeding-edge, high-powered gaming rig. This next program, Expensive Calculator, can turn that monster of a machine into a simple calculator. The program demonstrates built-in arithmetic operators. Figure 1.4 shows off the results.


image

Figure 1.4

Cรพรพ can add, subtract, multiply, divide, and even calculate a remainder.


You can download the code for this program from the Course Technology website (www.courseptr.com/downloads). The program is in the Chapter 1 folder; the filename is expensive_calculator.cpp.

// Expensive Calculator

// Demonstrates built-in arithmetic operators

14 Chapter 1 n Types, Variables, and Standard I/O: Lost Fortune


#include <iostream> using namespace std;


int main()

{

cout << "7 + 3 = " << 7 + 3 << endl;

cout << "7 - 3 = " << 7 - 3 << endl;

cout << "7 * 3 = " << 7 * 3 << endl;


cout << "7 / 3 = " << 7 / 3 << endl;

cout << "7.0 / 3.0 = " << 7.0 / 3.0 << endl;


cout << "7 % 3 = " << 7 % 3 << endl;


cout << "7 + 3 * 5 = " << 7 + 3 * 5 << endl; cout << "(7 + 3) * 5 = " << (7 + 3) * 5 << endl;


return 0;

}