Question

Write the function prototype and the definition of a function call "oddoreven" that determine if an...

Write the function prototype and the definition of a function call "oddoreven" that determine if an integer value is ODD or EVEN. The function will return a string containing that message. Use only ONE function! As an example if an integer value of 20 was passed to that function then the function will return "20 is an Even Number." if an integer value of 35 was passed to that function then the function will return "35 is an Odd Number."

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


#include <iostream>
#include <string>
using namespace std;

string oddoreven(int number);

int main() {
    int number;
    cout << "Enter a number: ";
    cin >> number;
    cout << oddoreven(number) << endl;
    return 0;
}

string oddoreven(int number) {
    string result = std::to_string(number);
    if (number % 2 == 0) {
        result += " is an Even Number.";
    } else {
        result += " is an Odd Number.";
    }
    return result;
}
Add a comment
Know the answer?
Add Answer to:
Write the function prototype and the definition of a function call "oddoreven" that determine if an...
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
  • Write a function prototype for a function that will accept a single integer. Create a function...

    Write a function prototype for a function that will accept a single integer. Create a function that accepts an integer and determines if the integer is odd or even. create a smsll program that asks a user for an integer and calls a function that determines if the integer is even or odd. This is a C language program.

  • Functions can return a string, not just an int or a float. Write a function called...

    Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a number:...

  • Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The...

    Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...

  • 1. Write a statement that calls a function named showSquare, passing the value 10 as an...

    1. Write a statement that calls a function named showSquare, passing the value 10 as an argument. 2. Write the function prototype for a function called showSquare. The function should have a single parameter variable of the int data type and areturn type of void. 3. Write the function prototype for a function called showScoreswith a parameter list containing four integer variables and a return type of void. 4. Look at the following function definition: double getGrossPay(int hoursWorked, double payRate)...

  • Write a function to check if a number is multiple of 3 The function name is...

    Write a function to check if a number is multiple of 3 The function name is isMultipleOf3 The function returns a Bool value The function takes one integer argument The function will check if the number passed in is a multiple of 3. If it is multiple of 3, return true, otherwise return false A number is multiple of 3 if it can be divided by 3 evenly, such as 3, 30, 15, 21, etc. You only need to write...

  • Write a function called isEven() that uses the remainder (modulus) operator (%) to determine when an...

    Write a function called isEven() that uses the remainder (modulus) operator (%) to determine when an integer is even. The function should take an integer argument called myNumber passed from within the for loop and return true if the integer is even and false otherwise. Your program should determine what numbers are even and odd from 1 to 20 using the isEven() function. Your counter variable in the for loop should be called num.

  • answer in c++ Using the table below, complete the C++ code to write the function prototype...

    answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...

  • 1. Write a function that converts a string into an int. Assume the int is between...

    1. Write a function that converts a string into an int. Assume the int is between 10 and 99. Do not use the atoi() or the stoi() function. 2. Write a function prototype for problem 1. 3. Write a function call for the function you defined in problem 1. 4. Write a function that converts an int between 10 and 99 into a string. 5. Write a function prototype for problem 4. 6. Write a function call for function you...

  • 4. Write a C definition (prototype) for a function called power which takes a float and...

    4. Write a C definition (prototype) for a function called power which takes a float and an integer as inputs, and returns a float as a result. 5. Write the body of the function from (4). This function should raise the first argument to the power of the second, by multiplying it by itself that many times (don’t use the inbuilt pow function, write your own). Do not worry about “special” cases like negative powers. Please do Q.5

  • by using matlab  Write a function that allows the user to insert an integer number, then return...

    by using matlab  Write a function that allows the user to insert an integer number, then return if the number is Even or zero or odd number.If the user insert non-integer number the function give error message.

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