Ask Question
6 December, 03:21

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.

+1
Answers (1)
  1. 6 December, 05:49
    0
    The program to this question as follows:

    Program:

    #include / /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"<
    }

    else if (bagOunces > 10)

    {

    cout << "Too large"<
    }

    else / /else block

    {

    cout << (bagOunces*6) <<" 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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Complete function PrintPopcornTime (), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too small". ...” 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