Concept explainers
A metric ton is 35,273.92 ounces. Write a
Weight of breakfast package
Program Plan:
- Include required header files.
- Initializes “const” variable “OUNCES_PER_METRICTON” to “35273.92”.
- Define main function,
- Declare three variables in “double” datatype.
- Declare a “char” variable for user option.
- Then performs “do-while” loop.
- Prompt statement for read the weight of packages in ounces.
- Read the weight of packages from user.
- Compute the weight in metric tons using “ounces/OUNCES_PER_METRICTON” and then store it in a variable “weightMetricTon”.
- Compute the number of boxes required to produce “1” metric ton using “OUNCES_PER_METRICTON/ounces” and then store it in a variable “no_of_boxes”.
- Display the weight in metric tons and number of boxes.
- Prompt statement for read the user option to continue the calculation.
- Read the user option.
- Check the user option using “while” loop. If the user entered option is equal to “y” or “Y” then continue the above process.
- Otherwise, the program terminated.
The below program is used to compute the weight of package of breakfast cereal in metric tons and number of boxes from the given weight of package in ounces
Explanation of Solution
Program:
//Header file
#include <iostream>
//For standard input and output
using namespace std;
/* Initializes the const variable "OUNCES_PER_METRICTON" to "35273.92" */
const double OUNCES_PER_METRICTON = 35273.92;
//Define main function
int main()
{
//Declare variables in type of "double"
double ounces, weightMetricTon, no_of_boxes;
//Declare variable in type of "char"
char option;
//Check the condition using "do-while" loop
do
{
/* Prompt statement for read the weight of package in ounces */
cout << "Enter the weight of package of breakfast cereal in ounces: ";
//Read the weight in ounces from user
cin>>ounces;
//Compute the given weight in metric ton
weightMetricTon = ounces/OUNCES_PER_METRICTON;
/* Compute the number of boxes required to produce "1" metric ton */
no_of_boxes = OUNCES_PER_METRICTON/ounces;
//Display the weight in metric tons
cout << "Weight of packets in metric tons: " << weightMetricTon << endl;
//Display the number of boxes
cout << "Number of boxes needed to yield 1 metric ton of cereal: " << no_of_boxes << endl;
//Prompt statement for asking the user choice
cout << "Enter 'y' or 'Y' to continue (OR) Enter any character to terminate: ";
//Read option from user
cin >> option;
}
/* If the user entered option is "y" or "Y", then continue the above process. Otherwise program terminated */
while (option == 'y' || option == 'Y');
return 0;
}
Output:
Enter the weight of package of breakfast cereal in ounces: 4000
Weight of packets in metric tons: 0.113398
Number of boxes needed to yield 1 metric ton of cereal: 8.81848
Enter 'y' or 'Y' to continue (OR) Enter any character to terminate: y
Enter the weight of package of breakfast cereal in ounces: 4820
Weight of packets in metric tons: 0.136645
Number of boxes needed to yield 1 metric ton of cereal: 7.31824
Enter 'y' or 'Y' to continue (OR) Enter any character to terminate: n
Want to see more full solutions like this?
Chapter 2 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting out with Visual C# (4th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Programming in C
Software Engineering (10th Edition)
Concepts Of Programming Languages
- Meadowdale Dairy Farm sells organic brown eggs to local customers. It charges $3.25 for a dozen eggs, or 45 cents for individual eggs that are not part of a dozen. Write a program that prompts a user for the number of eggs in the order and then display the amount owed with a full explanation using the following wording: You ordered 27 eggs. That’s 2 dozen at $3.25 per dozen and 3 loose eggs at 45 cents each for a total of $7.85. So far everything is right but something in my equations is causing my ouput to show up as 45.0arrow_forwardMeadowdale Dairy Farm sells organic brown eggs to local customers. It charges $3.25 for a dozen eggs, or 45 cents for individual eggs that are not part of a dozen. Write a program that prompts a user for the number of eggs in the order and then display the amount owed with a full explanation using the following wording: You ordered 27 eggs. That’s 2 dozen at $3.25 per dozen and 3 loose eggs at 45 cents each for a total of $7.85. write a program that calculates the following: The program calculates the cost of 12 egss The program calculates the cost of 35 eggs The program calculates the cost of 6 eggs JAVA import java.util.Scanner; class Eggs { public static void main(String[] args) { // Write your code here } }arrow_forwardWrite a program that computes the molecular weight of a carbohydrate (ingrams per mole) based on the number of hydrogen, carbon, and oxygenatoms in the molecule. The program should prompt the user to enter thenumber of hydrogen atoms, the number of carbon atoms, and the numberof oxygen atoms. The program then prints the total combined molecularweight of all the atoms based on these individual atom weights:Atom Weight(grams I mole)H 1.00794c 12.01070 15.9994For example, the molecular weight of water (H20) is: 2(1.00794) +15.9994 = 18.01528.arrow_forward
- Given the sample code above in generating a random number. Create a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don't display the computer's choice yet.) 2. The user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. (You can use a menu if you prefer.) 13. The computer's choice is displayed. 4. A winner is selected according to the following rules: a. If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors.) b. If one player chooses scissors and the other player chooses paper, then scissor wins. (Scissors cuts paper.) c. If one player chooses paper and the other player…arrow_forward2. Party shop sells birthday gift bags in two ways. set of 12 bags for $17.99 or an individual bag for $1.75. Customers can purchase a Write a complete program that asks the user input for the number of gift bags need to be purchased (an integer) and outputs the total price of the purchase. a) For example, if the customer buys 14 gift bags, the customer would be charged for 1 set of (12 bags) plus another 2 individual bags. The subtotal would be 1 (17.99) + 2 (1.75) = $21.49. b) Use a constant variable to set a fixed tax rate of 8.875. c) Display correct dollar values (2 decimal places, use cout precision). User input can be any content and it's bold and italicized for clarity. Example Output 1 Welcome to Party Shop! How many gift bags would you like to purchase: 14 SHOPPING CART 1-set (s) $17.99 2-individual $3.50 Subtotal: $21.49 Таx: $1.91 Total: $23.40 Thank you shopping Party Shop! Example Output 2 Welcome to Party Shop! How many gift bags would you like to purchase: 11 SHOPPING…arrow_forwardA company of 20 employees wants to find the employee who made the highest commission so he/she can be paid a 10% bonus of the commission he/she earned for that month. The commission an employee makes is calculated by multiplying the sales amount by the commission rate. The commission rates are shown below: Sales Amount Commission Less Than 40000 No commission 40000 to 80000 inclusive 5% Greater than 80000 10% Write a program to: Prompt the user for each employee’s id (an integer value) and the sales amount For each employee, display the commission earned Display the total commission earned by all the employees Display the average commission earned by an employee Display the employee id, the commission and the bonus paid to the employee with the highest commission Must be written in c++, no arrays to be used, only use iostream libraryarrow_forward
- The Café Noir Coffee Shop wants some market research on its customers. When a customer places an order, a clerk asks for the customer’s zip code and age. The clerk enters that data as well as the number of items the customer orders. The program operates continuously until the clerk enters a 0 for zip code at the end of the day. When the clerk enters an invalid zip code (more than 5 digits) or an invalid age (defined as less than 10 or more than 110), the program reprompts the clerk continuously. When the clerk enters fewer than 1 or more than 12 items, the program reprompts the clerk two more times. If the clerk enters a high value on the third attempt, the program accepts the high value, but if the clerk enters a negative value onthe third attempt, an error message is displayed and the order is not counted. At the end of the program, display a count of the number of items ordered by customers from the same zip code as the coffee shop (54984), and a count from other zip codes. Also…arrow_forwardYou arrive in front of a bridge that you must cross to reach a village before dark. Crossing the bridge is not free - the bridgekeeper asks you to roll two dice to determine the cost. You decide to write a program to verify that he is charging the right price. Your program should read two integers, between 1 and 6, representing the values of each die. If the sum is greater than or equal to 10, then you must pay a special fee (36 coins). Otherwise, you pay twice the sum of the values of the two dice. Your program must then display the text "Special tax" or "Regular tax" followed by the amount you have to pay on the next line.arrow_forwardHELP ME WRITE THIS CODEarrow_forward
- Write a program that helps a company manage salaries of its employees. Your program should ask for the number of hours worked and the hourly rate of an employee than, display the salary. This program should allow the user to enter the information of many employees until enters -1. Sample Run: Enter the number of hours worked (-1 to end): 32 Enter hourly rate of the worker: 100 Balary is 03200 Enter the number of hours Worked (-1 to end) : 40 Enter hourly rate of the worker: 5 Balary is 3200 Enter the number of hours worked (-1 to end): 42 Enter hourly rate of the worker: 10 Salary is 0420 Enter the number of hours worked (-1 to end) : -1arrow_forwardWrite a program to calculate the position of a projectile at a given time t. For an initial velocity vo and angle of departure ®g, the position is given by x and y coordinates as follows (note: the gravity constant g is 9.81 m/s²): X= V0 Cos (0)t y=vo sin (8,)t –; gt The program should initialize the variables for the initial velocity, time, and angle of departure. It should then call a function to find the x and y coordinates, and then another function to print the resultsarrow_forwardPart 1: Complete the survey. Part 2: Peek-a-boo is a fun game that little kids like to play. To simulate this game on the computer, write a program that will generate a random number between 1 and 4. Then, will print to the screen the animal name associated to that number. The animal names used will be: pig when a 1 is generated cow when a 2 is generated chicken when a 3 is generated horse when a 4 is generated If your program generates a 3, the output will be: chicken The player will then enter a 1 if they would like to play again or anything else to exit the program. If the player enters "1 1 1 0", the output will be: horse chicken cow horse For coding simplicity, follow each output animal by a space, even the last one. Hint: To make testing easier, seed your random number generator with 0.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education