ABSOLUTE C++

Absolute C++

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

 

Question by Anonymous on 09 Mar, 2016 at 05:37 AM

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 by Nethan on 09 Mar, 2016 at 05:37 AM

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 improve the above solution.