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.
#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);
}
Comments
Leave a comment