Ask Question
15 November, 08:02

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.

+1
Answers (1)
  1. 15 November, 08:12
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers