Question

C++ write a function named subtract that takes two integers as parameters and returns the result...

  • C++
  • write a function named subtract that takes two integers as parameters and returns the result of subtracting the second number from the first.
    • i.e. int1 - int2
  • Change subtract to have default arguments for its two parameters. Pick whatever non-zero numbers you would like.
  • Write a prototype for subtract before main so the program runs without error.
  • I cant figure out the part where you pass no parameters, I've tried to set defailt values for the parameters but it results in a compile error.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

using namespace std;

// declare prototype for function

int subtract(int int1, int int2);

int main()

{

    int int1, int2;

   

    cout<<"Enter 2 numbers : ";

   

    // get user input

    cin>>int1>>int2;

   

    cout<<"Subtract : "<<subtract(int1, int2);

   

    return 0;

}

int subtract(int int1, int int2)

{

    return int1 - int2;

}

Sample Output

Add a comment
Know the answer?
Add Answer to:
C++ write a function named subtract that takes two integers as parameters and returns the result...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT