Answer to Question #308132 in C++ for Harry

Question #308132

Write two functions:

A function named sum which takes two integer values as arguments, and returns their sum.

A main function which asks the user for two integer values, passes the two values to the sum function, then prints the two values and their sum.

The main function then again asks the user for two integer values, passes the two values to the sum function, then prints the two values and their sum.

Test it once, with the values 3 and 4, and then 5 and 49.


1
Expert's answer
2022-03-08T16:03:27-0500
#include <iostream>

using namespace std;

int sum(int i, int j)
{
	return i + j;
}

int main()
{
	int count = 0;
	int num1, num2;
	do
	{
		cout << "Please, enter the first value: ";
		cin >> num1;
		cout << "Please, enter the second value: ";
		cin >> num2;
		cout << "First value = " << num1;
		cout << "\nSecond value = " << num2;
		cout << "\nTheir sum = "<<sum(num1, num2)<<endl;
		count++;
	} while (count < 2);	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog