Answer to Question #195852 in C++ for SWB

Question #195852

1.    Create a function with the name “ten” that takes two arguments. Both arguments are integers, a and b. Return true if one of them is 10 or if their sum is 10. Variables should be taken by user in the main function.



1
Expert's answer
2021-05-21T10:54:49-0400
/******************************************************************************
    *C++ function with the name “ten” that takes two arguments. 
    *Both arguments are integers, a and b. 
    *Return true if one of them is 10 or if their sum is 10.


*******************************************************************************/


#include <iostream>


using namespace std;
//Function declaration
bool ten(int a, int b);
//Driver code
int main()
{
    int a, b;
    cout<<"Enter the first number: ";
    cin>>a;
    cout<<"Enter the second number: ";
    cin>>b;
    cout<<ten(a, b);
    


    return 0;
}
//Function definition
bool ten(int a, int b)
{
    //If either a or b is 10 or a+b is equal to 10
    if(a == 10 || b == 10 || (a + b) == 10)
    {
        //return true
        return true;
    }
}

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