Write a C++ program that reads in two integers and then outputs both their sum and their product. One way to proceed is to start with the program in Display 1.8 and to then modify that program to produce the program for this project. Be certain to type the first line of your program exactly the same as the first line in Display 1.8. In particular, be sure that the first line begins at the left-hand end of the line with no space before or after the # symbol. Also, be certain to add the symbols \n to the last output statement in your program. For example, the last output statement might be the following:
cout << "This is the end of the program.\n";
Program Code:
/Header file
#include <iostream>
using namespace std;
//main function
int main( )
{
//Variable declaration
int first_num,second_num,sum,product;
//Prompt the user to enter input
cout << "Enter first number: ";
cin >> first_num;
cout << "Enter second number: ";
cin >> second_num;
//Sum calculation
sum=first_num+second_num;
cout << "Sum of two numbers:"<<sum<<endl;
//Product calculation
product=first_num*second_num;
cout << "Product of two numbers:"<<product<<endl;
return 0;
}
Output:
Enter first number: 10
Enter second number: 20
Sum of two numbers:30
Product of two numbers:200