Ask Question
7 July, 15:18

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.

+5
Answers (1)
  1. 7 July, 18:23
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers