Chapter 2 – Q #7: Ocean Levels – Tony Gaddis – Starting Out With C++

Chapter 2 – Q #7:  Ocean Levels – Tony Gaddis – Starting Out With C++



PROBLEM:- 

Assuming the ocean s level is currently rising at about 1.5 millimeters per year, write a program that displays:

  • The number of millimeters higher than the current level that the ocean s level will be in 5 years.
  • The number of millimeters higher than the current level that the ocean s level will be in 7 years.
  • The number of millimeters higher than the current level that the ocean s level will be in 10 years.
SOLUTION:- 

#include <iostream>

using namespace std;

int main()

{

      const double raise_per_year = 1.5;

      double year_5 = raise_per_year * 5;

      double year_7 = raise_per_year * 7;

      double year_10 = raise_per_year * 10;

      cout << "Total Increase After 5 Years:  " << year_5 << endl;

      cout << "Total Increase After 7 Years:  " << year_7 << endl;

      cout << "Total Increase After 10 Years: " << year_10 << endl;

      return 0;

}


This is the solution of this question

Explanation of this Solution

  • I declare constant raise per year and initialize given value.
  • I declare year 5 variable and calculate value.
  • I declare year 7 variable and calculate value.
  • Then, year 10 variable and calculate value.
  • In last, Display output of all years on the screen.
  • Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File

Post a Comment

0 Comments