fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 5 P 294 #3
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Display Ocean's Rising Levels
  6.  * ____________________________________________________________________________
  7.  * This program will display how much the ocean level will have risen each year
  8.  * for the next 25 years based off of a constant rate of ocean rising.
  9.  *
  10.  * Formula used:
  11.  * totalRise = year * rise_per_year
  12.  * ____________________________________________________________________________
  13.  * Input
  14.  * rise_per_year //rate of ocean levels rising per year (millimeters)
  15.  * years //amount of years (up to 25)
  16.  * Output
  17.  * totalRise //total rise of ocean according to each year
  18.  *****************************************************************************/
  19. #include <iostream>
  20. #include <iomanip>
  21. using namespace std;
  22. int main()
  23. {
  24. double rise_per_year =1.5; //INPUT - constant rate of ocean levels rising 1.5 millimeters
  25. int years = 25; //INPUT - amount of years the table will go up to which is 25
  26. double totalRise; //OUTPUT - total rise of ocean based off the year
  27. //
  28. //Create Table
  29. cout << "Year \t Rise (millimeters)" << endl;
  30. cout << "-----------------------------" << endl;
  31. //
  32. //Calculation
  33. for (int year = 1; year <= years; year++){
  34. totalRise = year * rise_per_year;
  35. cout << setw(4) << year << "\t" << fixed << setprecision(1) << totalRise << endl;
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Year 	 Rise (millimeters)
-----------------------------
   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