answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mamont248
13 days ago
9

Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "To

o small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline. Example output for ounces = 7:42 seconds#include void PrintPopcornTime(int bagOunces) {}int main(void) {int userOunces;scanf("%d", &userOunces);PrintPopcornTime(userOunces);return 0;}2. Write a function PrintShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, print "Too few.". If more than 4, print "Too many.". Else, print "N: Lather and rinse." numCycles times, where N is the cycle number, followed by "Done.". End with a newline. Example output with input 2:1: Lather and rinse.2: Lather and rinse.Done. Hint: Declare and use a loop variable.#include /* Your solution goes here */int main(void) {int userCycles;scanf("%d", &userCycles);PrintShampooInstructions(userCycles);return 0;}

Computers and Technology
1 answer:
oksian1 [804]13 days ago
6 0

Response:

Function 1:

#include <stdio.h> //import input-output functionality

// this begins the function PrintPopcornTime body, accepting an integer variable //bagOunces as a parameter

void PrintPopcornTime(int bagOunces){

if (bagOunces < 3){ //check if bagOunces equals less than 3

printf("Too small"); //outputs Too small message

printf("\n"); } //prints a new line//The next else if executes when prior conditions are false and bagOunces surpasses 10

else if (bagOunces > 10){

    printf("Too large"); //outputs the message:  Too large     printf("\n");

//prints a new line

}/*else will run when bagOunces is nether under 3 nor over 10 */

else {

/* The subsequent three statements could store bagOunces * 6 in result for printing. However, you can simply use one print statement printf("%d",bagOunces * 6) instead */

    //int result;

    //result = bagOunces * 6;

    //printf("%d",result);

 printf("%d",bagOunces * 6); /calculates the value of bagOunces multiplied by 6

 printf(" seconds"); // "seconds" follows the value of bagOunces * 6

 printf("\n"); }}

//outputs a new line

int main(){

//initiating main function body

int userOunces; //defines integer variable userOunces

scanf("%d", &userOunces); //captures userOunces input

PrintPopcornTime(userOunces);

//calls PrintPopcornTime function with userOunces argument

return 0; }

Function 2:

#include <stdio.h>

//header for using input-output functions// this starts the function PrintShampooInstructions body with integer variable numCycles as

a parametervoid PrintShampooInstructions(int numCycles){

if(numCycles < 1){

//checks if numCycles is below 1 or not

printf("Too few.");

//outputs Too few if the condition is metprintf("\n"); }

//prints a new line

//else if executes when the condition fails, checking if numCycles exceeds 4

else if(numCycles > 4){

//outputs Too many if the above condition is accepted

printf("Too many.");

printf("\n"); } //prints a new line//else will handle when previous if and else if evaluations return false

else{

//outputs "N: Lather and rinse." numCycles times, with N presenting the cycle //number, finished with Done

for(int N = 1; N <= numCycles; N++){

printf("%d",N);

printf(": Lather and rinse. \n");}

printf("Done.");

printf("\n");} }

int main()

//start of the main function body

{    int userCycles;

//defines integer variable userCycles

   scanf("%d", &userCycles); //receives input for userCycles

   PrintShampooInstructions(userCycles); //executes the PrintShampooInstructions function with userCycles argument

   return 0;}

I will clarify the for loop present in PrintShampooInstructions() function. The loop initializes variable N to 1 and evaluates if N remains lesser than or equal to numCycles.

Suppose numCycles = 2. The condition holds true since N < numCycles confirming 1 < 2, thus entering the loop's body. Following statements appear:

printf("%d",N); outputs the value of N followed by printf(": Lather and rinse. \n"); which will print Lather and rinse along with a newline \n.

Initially, this line emerges on the screen as:

1: Lather and rinse.After which, N is enhanced by 1 making it 2 (i.e. N = 2).[TAG_191] During the second iteration:

The loop assesses if N remains below or equal to numCycles. We know numCycles = 2. As the condition is satisfied, the flow of control commences into the loop’s body.

printf("Done."); articulates Done after the preceding two lines are printed.Now, the subsequent check leads to if N remains lower than or equal to numCycles. Noticing that N now reads 3 or greater than 2 thus terminating the loop. The result is:

printf("Done.");

displays Done on the screen.

The collective output is visualized as:1: Lather and rinse.2: Lather and rinse.

Done.

The accompanying programs with their outputs are attached.

You might be interested in
Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per li
zubka84 [945]

Answer:

The following program is written in python programming language:

amount = int(input("Enter Amount: "))

#Check if the input is less than 1

if amount<=0:

print("No Change")

else: #If input is valid

#Convert input into different coins

dollar = int(amount/100) #Dollar conversion

amount = amount % 100 #Calculate remainder

quarter = int(amount/25) #Quarter conversion

amount = amount % 25 #Calculate remainder

dime = int(amount/10) #Dime conversion

amount = amount % 10 #Calculate remainder

nickel = int(amount/5) #Nickel conversion

penny = amount % 5 #Calculate remainder

#Display results

if dollar >= 1:

if dollar == 1:

print(str(dollar)+" dollar")

else:

print(str(dollar)+" dollars")

if quarter >= 1:

if quarter == 1:

print(str(quarter)+" quarter")

else:

print(str(quarter)+" quarters")

if dime >= 1:

if dime == 1:

print(str(dime)+" dime")

else:

print(str(dime)+" dimes")

if nickel >= 1:

if nickel == 1:

print(str(nickel)+" nickel")

else:

print(str(nickel)+" nickels")

if penny >= 1:

if penny == 1:

print(str(penny)+" penny")

else:

print(str(penny)+" pennies")

Explanation:

The program is implemented using python and includes comments for clarification.

The variable amount is defined as an integer.

The check in line 3 determines if the amount is less than or equal to 0.

If it is, "No Change" is printed.

If not, it converts the entered amount into smaller coins.

Line 7 converts the input amount to its dollar counterpart.

Line 8 calculates the remainder.

Line 9 converts the remainder to quarters.

Line 10 calculates the new remainder.

Line 11 converts the current remainder to dimes.

Line 12 calculates the adjusted remainder.

Line 13 calculates the nickel equivalent.

Line 14 gets the penny equivalent of what's left.

Lines 16 and beyond display the result using the correct terminology (singular or plural).

3 0
26 days ago
Write a program that prompts the user to enter three cities and displays them in ascending order. Here is a sample run: Enter th
amid [805]

Answer:

import java.util.Scanner;

public class SortStrings3 {

   public static void main(String args[]){

       Scanner scanner = new Scanner(System.in);

       String str1, str2, str3;

       System.out.print("Enter the first city: ");

       str1 = scanner.nextLine();

       System.out.print("Enter the second city: ");

       str2 = scanner.nextLine();

       System.out.print("Enter the third city: ");

       str3 = scanner.nextLine();

       System.out.print("The three cities in alphabetical order are ");

       if(str1.compareTo(str2) < 0 && str1.compareTo(str3) < 0){

           System.out.print(str1+" ");

           if(str2.compareTo(str3) < 0){

               System.out.print(str2+" ");

               System.out.println(str3);

           }

           else {

               System.out.print(str3+" ");

               System.out.println(str2);

           }

       }

       else if(str2.compareTo(str1) < 0 && str2.compareTo(str3) < 0){

           System.out.print(str2+" ");

           if(str1.compareTo(str3) < 0){

               System.out.print(str1+" ");

               System.out.println(str3);

           }

           else {

               System.out.print(str3+" ");

               System.out.println(str1);

           }

       }

       else{

           System.out.print(str3+" ");

           if(str1.compareTo(str2) < 0){

               System.out.print(str1+" ");

               System.out.println(str2);

           }

           else {

               System.out.print(str2+" ");

               System.out.println(str1);

           }

       }

   }

}

EXPLANATION:

The task requires creating a program that will prompt users to input three cities named Atlanta, Chicago, and Los Angeles (which are to be sorted in ascending alphabetical order).

Thus, we're going to develop the code using a programming language called JAVA (JUST ANOTHER VIRTUAL ACCELERATOR).

We chose Java for this task because it is capable of loading, validating, and executing code on either single or multiple servers.

The code can be found in the attached document/file. Please take a look at it.

Download doc
3 0
16 days ago
Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input.
Amiraneli [921]

Answer:

In C++:

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

int main(){

   string lname, fname, stringnum;    int num; string login, pwd;

   cout<<"Last Name: ";    cin>>lname;

   cout<<"First Name: ";    cin>>fname;

   cout<<"Four-digit integer: ";    cin>>num;

   stringnum = to_string(num).substr(0, 4);

   stringstream geek(stringnum);    geek>>num;

   num = num%100;

   pwd = to_string(num);

   if(lname.length()<5){ login = lname + fname.substr(0, 1);    }

   else{ login = lname.substr(0, 5) + fname.substr(0, 1);    }

   cout<<"Login Name: "<<login<<endl;

   cout<<"Password: "<<pwd<<endl;

   return 0;

}

Explanation:

This initializes all the required variables

   string lname, fname, stringnum;    int num;     string login, pwd;

This asks the user for their last name

   cout<<"Last Name: ";    cin>>lname;

This asks for the first name of the user

   cout<<"First Name: ";    cin>>fname;

This prompts for a four-digit number

   cout<<"Four-digit integer: ";    cin>>num;

This converts the number into a string and extracts the first four digits

   stringnum = to_string(num).substr(0, 4);

This changes the string back into an integer

   stringstream geek(stringnum);    geek>>num;

This extracts the last two digits of the four-digit number

   num = num%100;

This generates the user's password

  pwd = to_string(num);

This constructs the user's login name.

This block runs if the last name has fewer than five letters

   if(lname.length()<5){ login = lname + fname.substr(0, 1);    }

This block runs otherwise

   else{ login = lname.substr(0, 5) + fname.substr(0, 1);    }

This displays the login name

   cout<<"Login Name: "<<login<<endl;

This displays the password

   cout<<"Password: "<<pwd<<endl;

3 0
1 month ago
Debug the program so it prints the factorial of a positive integer entered by the user. This is calculated by multiplying all th
Natasha_Volkova [897]
The primary issue was declaring int prod within the while loop, which caused prod to reset to 1 each time the loop executed.
3 0
21 day ago
Sketch the developments in multimedia. What do you expect to be the commercial impact of multimedia in the (near) future?
Natasha_Volkova [897]

Answer:

Multimedia has become an essential and vital part of various sectors such as healthcare, education, entertainment, and marketing.

Explanation:

In the past, children primarily learned using textbooks, but now they engage with smart boards and other interactive digital devices that provide animated content.

The role of multimedia is crucial in entertainment, where there has been a significant increase in attendance for multimedia events.

Similarly, in the medical field, students can learn more effectively with the use of multimedia tools. Looking ahead, multimedia is expected to draw interest across all disciplines and its future seems promising.

4 0
17 days ago
Other questions:
  • In the Scrum board, prioritizing the issue backlog is done in the ———- mode.
    7·1 answer
  • Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
    12·1 answer
  • Q) Select the two obstacles for data parsing
    5·2 answers
  • To reduce costs and the environmental impact of commuting, your company decides to close a number of offices and to provide supp
    14·1 answer
  • Edhesive 2.3 code practice question 1​
    11·1 answer
  • Remember for a moment a recent trip you have made to the grocery store to pick up a few items. What pieces of data did the Point
    10·1 answer
  • The principal that users have access to only network resources when an administrator explicitly grants them is called __________
    6·1 answer
  • Allison wants to use equations to simplify the process of explaining something to the Sales team, but the default eq
    8·2 answers
  • James is an intern in a film production company. On his first day, James’ boss, Monica, tells him, “Before anything else, let me
    9·1 answer
  • Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. PLEASE DONT F
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!