fork download
  1. //Dione Torrevillas CS1A Chapter 5, P. 294, #3
  2. //
  3. /**********************************************************************
  4.  *
  5.  * OCEAN LEVELS
  6.  *
  7.  * This program displays the amount the ocean level will rise
  8.  * each year for the next 25 years. The ocean level is assumed
  9.  * to rise 1.5 millimeters each year.
  10.  *
  11.  * Computation is based on the formula:
  12.  * Ocean Rise = Year x 1.5 millimeters
  13.  *
  14.  * INPUT
  15.  * None
  16.  *
  17.  * OUTPUT
  18.  * oceanRise : Total ocean level rise for each year
  19.  *
  20.  **********************************************************************/
  21.  
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25.  
  26. int main()
  27. {
  28. const double RISE_PER_YEAR = 1.5; //CALC - Rise each year in millimeters
  29. int year; //CALC - Loop counter
  30. double oceanRise; //OUTPUT - Total rise in millimeters
  31.  
  32. //
  33. // Output Table Heading
  34. //
  35. cout << "Year\tOcean Level Rise (mm)" << endl;
  36. cout << "-----------------------------" << endl;
  37.  
  38. //
  39. // Compute and Output Ocean Rise
  40. //
  41. for (year = 1; year <= 25; year++)
  42. {
  43. oceanRise = year * RISE_PER_YEAR;
  44.  
  45. cout << year << "\t"
  46. << fixed << setprecision(1)
  47. << oceanRise << endl;
  48. }
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Year	Ocean Level 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