/* Ocean Levels - This program assumes that the ocean's level is currently rising
at about 1.5mm per year. It displays a table showing the number of millimeters
that the ocean will have risen each year for the next 25 years. */
#include "Utility.h"
int main()
{
/* Constant: Ocean level, Years total */
const double OCEAN_LEVEL = 1.5;
const int YEARS_TOTAL = 24;
/* Variable: Year (counter variable), Risen total */
int year = 0;
double risenTotal = 0;
/* Display: Introduction */
cout << "The ocean level has risen more or less stably at about 1.5 mm\n"
<< "per year. Assuming that the rise will remain at this rate, the\n"
<< "following table will show the predicted rise of the ocean level\n"
<< "in a period of 25 years.\n\n";
/* Display: A formatted table header */
cout << "Year" << "\t\t\t\t" << "Ocean Level\n"
<< "--------------------------------------------\n";
/* For loop */
for (year = 1; year <= YEARS_TOTAL; year++)
{
/* Calculation */
risenTotal = (year * OCEAN_LEVEL);
/* Display: The formatted output of rise of levels 24 times */
cout << fixed << showpoint << setprecision(1);
cout << "In year " << year << "\t\t\t" << "The rise was: "
<< setw(4) << right << risenTotal << " mm" << endl;
}
/* Display the total rise by adding OCEAN_LEVEL (1.5) to risenTotal (36.0) */
cout << "--------------------------------------------\n";
cout << "After " << year << " years the ocean level will rise by: " << (risenTotal + OCEAN_LEVEL) << " mm\n";
pauseSystem();
return 0;
}
Tuesday, December 6, 2016
Programming Challenge 5.3 - Ocean Levels
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment