/* 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 double num1 = 0; double num2 = 0; double sum = 0; double diff = 0; double prod = 0; double quot = 0.0; // get input from user cout << "Enter two non-zero numbers (separated by a blank): "; cin >> num1 >> num2; sum = num1 + num2; diff = num1 - num2; prod = num1 * num2; quot = 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 " << quot << '\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 numbers (separated by a blank): 5.3 2.7 5.3+2.7 is 8 5.3-2.7 is 2.6 5.3*2.7 is 14.31 5.3/2.7 is 1.96296 Press Enter to continue... */