Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline.

Respuesta :

Answer:

The program to this question as follows:

Program:

#include <iostream> //defining header file

using namespace std;

void PrintPopcornTime(int bagOunces) //defining method PrintPopcornTime that accepts bagOunces

{

//defining conditional statement

if (bagOunces < 3) //if block checks bagOunces less then 3  

{

cout << "Too small"<<endl;

}

else if (bagOunces > 10)

{

cout << "Too large"<<endl; //else if value greater than 10

}

else //else block

{

cout << (bagOunces*6) <<" seconds"<<endl; //calculate seconds

}

}

int main()  

{

int bagOunces; //defining integer variable bagOunces

cout<<"Enter number: "; //message

cin>>bagOunces; //input value by user

PrintPopcornTime(bagOunces); //calling the method

return 0;

}

Output:

Enter number: 3

18 seconds

Explanation:

In the above C++ language code, the first header file is defined, then the method "PrintPopcornTime" is defined, in this method, an integer variable "bagOunces" is passed as a parameter, inside the method a conditional statement is used that can be described as follows:

  • In the if block, it will check that the "bagOunces" variable value is less than 3, if it is true, it will print "Too small". otherwise, it will go else if block.
  • In else if the "bagOunces" variable value is greater then 10, if it is true, it will print "Too large", otherwise it will go else block.
  • In the else block it will calculate the total second and prints its value in new line.

In the next step, the main method is defined, inside this method, an integer variable "bagOunces" is defined, which is used for user input and inside this method, the PrintPopcornTime is called.

Answer:

if(bagOunces < 2){

      System.out.println("Too small");

  }

  else if(bagOunces > 10){

      System.out.println("Too large");

  }

  else{

      System.out.println(6*bagOunces+" seconds");

  }

Explanation:

Ver imagen DarthVaderBarbie