Question

Write a function that takes an int as an argument and returns true if the int...

Write a function that takes an int as an argument and returns true if the int is an even number and false if not. In any case change the value of the original argument to twice its value. Use the integers 0 through 4 as test cases. Do not use any arrays.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include <iostream>
using namespace std;
bool Check(int number) //Check() fucntion which takes a number as an argumnet
{
  
if (number%2==0) //if a number is divisible by 2 i. even then return true and print the twice of the given nuumber
{
cout << "Twice of the original value " << number << " is " << 2*number << endl;
return true;
}
else{ //else print the twice of the given number and return false
cout << "Twice of the original value " << number << " is " << 2*number << endl;
return false;
}
}
int main()
{

int n;
cout << "Enter a number: "; //asking user to enter a number
cin >> n;
int val=Check(n); //calling Check() function by passing n value and storing the result in val
if (val==0)
cout << "False"; //if val is 0 print false
else
cout << "True"; //else print True
return 0;
}
Code and Output Screenshots:

Note: if you have any queries please post a comment thanks a lot..always available to help you...

Add a comment
Know the answer?
Add Answer to:
Write a function that takes an int as an argument and returns true if the int...
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
ADVERTISEMENT