Ask Question
16 June, 12:32

Write the definition of a method printAttitude, which has an int parameter and returns nothing. The method prints a message to standard output depending on the value of its parameter. If the parameter equals 1, the method prints disagree. If the parameter equals 2, the method prints no opinion. If the parameter equals 3, the method prints agree. In the case of other values, the method does nothing. Each message is printed on a line by itself.

+3
Answers (1)
  1. 16 June, 16:02
    0
    We can use nested else if.

    Explanation:

    Nested else if are used when we have multiple checks on single variable and at the end if no check is passed then we execute the else part of nested if.

    Code Example

    #include / /for input and output

    using namespace std;

    void printAttitude (int value) {

    if (value = = 1) {

    cout<<"disagree";

    }

    else if (value = =2)

    {

    cout<<"no opinion";

    }

    else if (value = =3) {

    cout<<"agree";

    } else {

    / / method do nothing

    }

    }

    int main ()

    {

    int option;

    cout<<"Enter your value : ";

    cin>>option;

    printAttitude (option);

    return 0;

    }

    Output

    Case 1:

    Enter your value : 1

    disagree

    Case 2:

    Enter your value : 2

    no option

    Case 3:

    Enter your value : 3

    agree

    Case 4:

    Enter your value : 1
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the definition of a method printAttitude, which has an int parameter and returns nothing. The method prints a message to standard ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers