97.9k views
4 votes
Write the definition of a function printAttitude, which has an int parameter and returns nothing. The function prints a message to standard output depending on the value of its parameter.If the parameter equals 1, the function prints disagreeIf the parameter equals 2, the function prints no opinionIf the parameter equals 3, the function prints agreeIn the case of other values, the function does nothing.Each message is printed on a line by itself.

1 Answer

2 votes

Answer:

// code in C++.

#include <bits/stdc++.h>

using namespace std;

// function to print attitude

void printAttitude(int n)

{

// if input is 1

if(n==1)

cout<<"disagree"<<endl;

// if input is 2

else if(n==2)

cout<<"no opinion"<<endl;

// if input is 3

else if(n==3)

cout<<"agree"<<endl;

}

// main function

int main()

{ // variable

int n;

cout<<"Enter a number:";

// read the input number

cin>>n;

// call the function

printAttitude(n);

return 0;

}

Step-by-step explanation:

Read a number from user and assign it to "n".Then call the function printAttitude() with parameter "n".In this function, if the input number is 1 then it will print "disagree", if the input number is 2 then it will print "no opinion" and if the input number is 3 then it will print "agree".function will do nothing if the input number is anything else.

Output:

Enter a number:2

no opinion

User Unom
by
5.2k points