fork download
  1. //Ryan Shahriyarpour CS1A Carl Argila CH5 HW Q:2
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Ocean Levels
  6.  *
  7.  *********************
  8.  *
  9.  * the ocean's level is currently rising at about 1.5 millimeters
  10.  * per year, and this program displays a table showing the number of millimeters
  11.  * that the ocean will have risen each year for the next 25 years.
  12.  *
  13.  * INPUT
  14.  * None (fixed values used)
  15.  *
  16.  * OUTPUT
  17.  * Table showing year and ocean level rise
  18.  *
  19.  ****************************************************************************/
  20.  
  21. #include <iostream>
  22. #include <iomanip>
  23. using namespace std;
  24.  
  25. int main()
  26. {
  27. const double RISE_PER_YEAR = 1.5;
  28.  
  29. cout << "Year\t\tOcean Rise (mm)\n";
  30. cout << "---------------------------------------\n";
  31.  
  32. // Display ocean rise for each of the next 25 years
  33. for (int year = 1; year <= 25; year++)
  34. {
  35. double totalRise = year * RISE_PER_YEAR;
  36. cout << year << "\t\t" << fixed << setprecision(1) << totalRise << endl;
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Year		Ocean Rise (mm)
---------------------------------------
1		1.5
2		3.0
3		4.5
4		6.0
5		7.5
6		9.0
7		10.5
8		12.0
9		13.5
10		15.0
11		16.5
12		18.0
13		19.5
14		21.0
15		22.5
16		24.0
17		25.5
18		27.0
19		28.5
20		30.0
21		31.5
22		33.0
23		34.5
24		36.0
25		37.5