SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

ABSOLUTE C++

Absolute C++

Authors:
Walter Savitch ,kenrick Mock
Exercise:
Programming Projects
Chapter:
C++ Basics
Edition:
5
ISBN:
9780132846813
Question:
1

 

Question

A metric ton is 35,273.92 ounces. Write a program that will read the weight of a package of breakfast cereal in ounces and output the weight in metric tons as well as the number of boxes needed to yield one metric ton of cereal.

Answer

Program Code:

#include <iostream>
using namespace std;
int main ( )
{
	//Variables declaration
	double const METRIC_TON = 35273.92;
	double ounce,boxes;
	double weight;
	double numOfBoxex;

	//Prompt and read the input from the keyboard
	cout<<"Enter the weight of a package of breakfast cereal in ounces:";
	cin>>ounce;

	//Calculate the weight in metric tons and display it
	weight = ounce/METRIC_TON;
	cout<<"The weight of the cereal: "<<weight<<endl;
	
	//Calculate the the number of boxes needed to yield one 
	//metric ton of cereal and display it
	numOfBoxex = METRIC_TON/ounce;
	cout<<"The number of boxes of cereal that will hold a ton: "<<numOfBoxex<<endl;
	system("PAUSE");
	return 0;
}

Output:

Enter the weight of a package of breakfast cereal in ounces:100

The weight of the cereal: 0.00283496

The number of boxes of cereal that will hold a ton: 352.739

2 0

Discussions

Post the discussion to improve the above solution.