fork download
  1. //Cecilia Rangel CSC5 Chapter 5, P.294, #3
  2. //
  3. /**************************************************************
  4.  *
  5.  * CHART OCEAN LEVELS
  6.  * ____________________________________________________________
  7.  * This program will ask for the user to input a positive
  8.  * number, and the program adds up all numbers between 0
  9.  * and the number inputted
  10.  *
  11.  *_____________________________________________________________
  12.  * CONSTANT
  13.  * rise : 1.5 - ocean rises 1.5 mm each year
  14.  *
  15.  * OUTPUT
  16.  * table : table chart showing the total rise
  17.  * accumulating each year
  18.  *
  19.  *
  20.  **************************************************************/
  21. #include <iostream>
  22. using namespace std;
  23.  
  24. int main() {
  25. const float rise = 1.5; //constant mm rise
  26. float accumulator = 1.5; //accumulation each year
  27. int year = 1; //year counter
  28.  
  29. //table header
  30. cout << "Year | Rise in millimeters" << endl;
  31. cout << "-------------------------" << endl;
  32.  
  33. while (year != 26)
  34. {
  35. cout << year << " ";
  36. cout << accumulator << endl;
  37.  
  38. year++;
  39. accumulator += rise;
  40. }
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Year  |  Rise in millimeters
-------------------------
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