Translate

Code Sampe: Write program that asks user to enter two integers

This sample is how to Write a program that asks the user to enter two numbers, obtains the two numbers from the user and prints the sum, product, difference, and quotient of the two numbers.


Exercise 1.23 Solution
#include <iostream>

using maespace std;
int main()

{
int num1, num2; // declare variables
cout << "Enter two integers: "; // prompt user
cin >> num1 >> num2; // read values from keyboard

// output the results
cout << "The sum is " << num1 + num2
<< "\nThe product is " << num1 * num2
<< "\nThe difference is " << num1 - num2
<< "\nThe quotient is " << num1 / num2 << endl;

return 0; // indicate successful termination
}

No comments:

Post a Comment