/* DemoOperators2.cpp CIS 150 5/29/2008 David Klick This program demonstrates type casting, simple math operators, and the results of integer division. */ #include using std::cin; using std::cout; using std::endl; void cont(); int main() { // declare and initialize variables int num1 = 0; int num2 = 0; int sum = 0; int diff = 0; int prod = 0; int rem = 0; int intQuot = 0; double quot = 0.0; // get input from user cout << "Enter two non-zero integers (separated by a blank): "; cin >> num1 >> num2; sum = num1 + num2; diff = num1 - num2; prod = num1 * num2; intQuot = num1 / num2; rem = num1 % num2; // result is double since we cast one of the ints to a double quot = (double)num1 / num2; // display results cout << num1 << '+' << num2 << " is " << sum << '\n'; cout << num1 << '-' << num2 << " is " << diff << '\n'; cout << num1 << '*' << num2 << " is " << prod << '\n'; cout << num1 << '/' << num2 << " is " << intQuot << '\n'; cout << num1 << '/' << num2 << " is " << quot << " (num1 cast to be a double)\n"; cout << num1 << '%' << num2 << " is " << rem << '\n'; cont(); return 0; } void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press Enter to continue..."; cin.get(); return; } /* Sample output: Enter two non-zero integers: 5 2 5+2 is 7 5-2 is 3 5*2 is 10 5/2 is 2 5/2 is 2.5 (num1 cast to be a double) 5%2 is 1 */