In C++
1) Write the function definition that has 1 pass by value integer parameter. The function contains logic to return true if the parameter is even and false if it is not.
2 ) Write a main function that prompts the user for a value, calls the function that you created in step one with the value entered by the user, display "even" if the function return true and otherwise displays "odd"
#include <iostream>
using namespace std;
//function to check passed value is even or not
bool oddEven(int val)
{
if(val%2==0)
return true;
return false;
}
int main()
{
//variable declaration
int num;
//get user input
cout<<"Enter a number: ";
cin>>num;
//function calling and display result
if(oddEven(num))
{
cout<<"even";
}
else
{
cout<<"odd";
}
return 0;
}
OUTPUT:
RUN 1:
Enter a number: 8
even
RUN 2:
Enter a number: 15
odd
Get Answers For Free
Most questions answered within 1 hours.