Write a C++ program to do the following: Define a function called \"difference\"
ID: 3688025 • Letter: W
Question
Write a C++ program to do the following:
Define a function called "difference" that can accept two integer values as arguments and returns an integer (which is the obtained by subtracting the first the second argument from the first argument.
Declare two variables in the main function and assign them values 7 and 10.
Call the difference function with the above created variables as arguments. Print the returned difference in the main function.
Call the function again with 11 and 5 as arguments and print the obtained difference.
Print the two differences on separate lines.
Explanation / Answer
#include<iostream>
using namespace std;
int Sub(int output1, int output2)
{
return output1 - output2;
}
int main()
{
int answer, input1, input2;
cout << "Give a integer number:";
cin >> input1;
cout << "Give another integer number:";
cin >> input2;
answer = Sub(input1,input2);
cout << input1 << " - " << input2 << " = " << answer;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.