Assume that 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 and the number of hot dogs each person will be given. The program should display the following details:
1. The minimum number of packages of hot dogs required
2. The minimum number of packages of hot dog buns required
3. The number of hot dogs that will be left over
4. The number of hot dog buns that will be left over

Respuesta :

Answer:

// This program is written in C++ programming language

// Comments are used for explanatory purpose

// The program starts here

#include<iostream>

using namespace std;

int main ()

{

// Initialise variables

int hotdog = 10;

int buns = 8;

//Prompt to enter the number of people and the number of hotdog per person

int numb, person;

cout<<"Number of People: ";

cin>>numb;

cout<<"Hot dog per person: ";

cin>>person;

// A. Calculating number of packages of required hot dogs

int numhotdog;

numhotdog = numb * person;

int pack, leftover, bunspack, bunsleft;

// Calculating Minimum Number of Packets

if(numhotdog/hotdog == numhotdog)

{

pack = numhotdog;

leftover = 0;

}

else

{

pack = numhotdog;

leftover = hotdog - numhotdog%hotdog;

}

// Calculating Minimum Number of Packets

if(numhotdog/buns == numhotdog)

{

bunspack = numhotdog;

bunsleft = 0;

}

else

{

bunspack = numhotdog;

bunsleft = buns - numhotdog%buns;

}

// Printing Results.

cout<<"Minimum Hot dog required. "<<pack;

cout<<"Minimum Hot dog Buns required. "<<bunspack;

cout<<"Leftover Hot dog required. "<<left;

cout<<"Leftover Hot dog buns required. "<<bunsleft;

return 0;

}

ACCESS MORE