SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Introduction To Computers And C++ Programming
Exercise:
Programming Projects
Question:5 | ISBN:9780321531346 | Edition: 7

Question

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";

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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
0 0

Discussions

Post the discussion to improve the above solution.