Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote