// Assume hot dogs come in packages of 10, and hot dog buns come in packages of 8.

// Write a program that calculates the number of packages of hot dogs and the

// number of packages of hot dog buns needed for a cookout, with the minimum amount

// of leftovers. The program should ask the user for the number of people attending

// the cookout. Assume each person will eat 1 hotdog.

//

// The program should display the following details:

//

// The minimum number of packages of hot dogs required

// The minimum number of packages of hot dog buns required

// The number of hot dogs that will be left over

// The number of hot dog buns that will be left over

//

// Hint: You might want to use the % operator in one of your calculation

//

function packagesNeeded(numberOfPeople, itemsPerPack) {

Respuesta :

Answer:

I am writing the JavaScript program Let me know if you want the program in some other programming language.

function packagesNeeded(numberOfPeople, itemsPerPack)  

{  return (numberOfPeople * itemsPerPack); }

  var noOfPpl= prompt("Enter the number of people attending the cookout:");  

var hotdogsNeeded = packagesNeeded(noOfPpl, 1)

var hotdog_pack = 10;

var bun_pack = 8;  

hotdog_packs_required = Math.ceil(hotdogsNeeded / hotdog_pack);  

console.log('The minimum number of packages of hot dogs required: ' + (hotdog_packs_required));  

hotdogs_leftover = hotdog_packs_required * hotdog_pack - hotdogsNeeded;  

console.log('The number of hot dog buns that will be left over: ' + (hotdogs_leftover));  

  bun_packs_required = Math.ceil(hotdogsNeeded / bun_pack);  

 console.log('The minimum number of packages of hot dog buns required: ' + (bun_packs_required));      

   bunPacksleftover = bun_packs_required * bun_pack - hotdogsNeeded;  

 console.log('The number of hot dog buns that will be left over: ' + (bunPacksleftover));

Explanation:

The function packagesNeeded() takes two arguments numberOfPeople which contains the number of people attending  the cookout and itemsPerPack contains 1 as each person will eat 1 hot dog.

Then the program prompts the user to enter the number of people attending  the cookout and stores this number in noOfPpl. prompt() function is used to take input from the user.

hotdogsNeeded variable holds the result produced by packagesNeeded which is passed two arguments number of people attending cookout and 1. variable  hotdog_pack = 10 and variable bun_pack = 8 as given that the  hot dogs come in packages of 10, and hot dog buns come in packages of 8.

In order to find the hot dog packages required, the required hot dogs is divided by the pack of hot dog. Math.ceil() function is used here to round the result of this division up to the next largest integer.

In order to computer number of hot dogs that will be left over, the the hot dogs required is subtracted from the product of required hot dog packages and hot dog pack.

The same calculations and formulas are used to compute the minimum number of packages of hot dog buns required  and number of hot dog buns that will be left over . The only difference is that it will be computed using bun_pack= 8 as the buns come in the pack of 8.

Output:

The minimum number of packages of hot dogs required: 1

The number of hot dog buns that will be left over: 0

The minimum number of packages of hot dog buns required: 2

The number of hot dog buns that will be left over: 6

The screenshot of the code along with its output is attached.

Ver imagen mahamnasir
Ver imagen mahamnasir
RELAXING NOICE
Relax