fork download
  1. //Zachary Abdollahi CS1A Chapter 5, P. 294, #3
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * CALCULATING OCEAN LEVELS
  6.  *
  7.  * _____________________________________________________________________________
  8.  * This program displays a table showing the number of millimeters the ocean
  9.  * level will have risen each year for the next 25 years, assuming a rise of
  10.  * 1.5 millimeters per year.
  11.  *
  12.  * INPUT
  13.  * None
  14.  *
  15.  * OUTPUT
  16.  * Table of year numbers and total millimeters risen
  17.  *
  18.  ******************************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21. int main()
  22. {
  23. const double RISE_PER_YEAR = 1.5; //Millimeters the ocean rises per year
  24. double totalRise; //OUTPUT - Total millimeters risen by a given year
  25.  
  26. // Display table header
  27. cout << "Year\tMillimeters Risen" << endl;
  28.  
  29. // Loop through years 1 to 25
  30. for (int year = 1; year <= 25; year ++)
  31. {
  32. totalRise = year * RISE_PER_YEAR;
  33. cout << year << "\t" << totalRise << endl;
  34. }
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Year	Millimeters Risen
1	1.5
2	3
3	4.5
4	6
5	7.5
6	9
7	10.5
8	12
9	13.5
10	15
11	16.5
12	18
13	19.5
14	21
15	22.5
16	24
17	25.5
18	27
19	28.5
20	30
21	31.5
22	33
23	34.5
24	36
25	37.5