Write a C++ program that takes two integers as input from the user and calculates their product.
Input and Output Examples
- Input: 5, 10 Output: The product is 50.
- Input: -3, 7 Output: The product is -21.
Algorithm
- Prompt the user to input two integers.
- Read the input values.
- Multiply the two numbers.
- Display the result to the user.
Below is the C++ code that multiplies two numbers:
#include <iostream>
using namespace std;
int main() {
int num1, num2, product;
// Step 1: Prompt the user to input two integers
cout << "Enter two numbers: ";
// Step 2: Read the input values
cin >> num1 >> num2;
// Step 3: Multiply the two numbers
product = num1 * num2;
// Step 4: Display the product to the user
cout << "The product is " << product << ".";
return 0; // Successful completion of the program
}
Testing with Different Input Values
The program can handle any integer values, including negative numbers and zeros, producing accurate results in all cases.
Input and Output Examples for Modified Program:
- Input: -4, -8 Output: The product is 32.
- Input: 0, 100 Output: The product is 0.