52.8k views
3 votes
This program will calculate the rise in ocean levels over 5, 10, and 50 years, Part of the program has been written for you. The part that has been written will read in a rise in ocean levels (per year) in millimeters. This value is read into a variable of type double named risingLevel. You will be completing the program as follows Output the value in risingLevel. This should be the first line of output. The output should be as follows (assume risingLevel has a value of 2.1) Level: 2.1 The number of millimeters higher than the current level that the ocean's level will be in 5 years (assuming the ocean is rising at the rate of risingLevel per year). This is your second line of output. The output will be as follows Years: 5, Rise: 10.5 The number of millimeters higher than the current level that the ocean's level will be in 10 years (assuming the ocean is rising at the rate of risingLevel per year). This is your third line of output. The output will be as follows (for a risingLevel" of 2.1 Years: 10, Rise: 21 The number of millimeters higher than the current level that the ocean's level will be in 50 years (assuming the ocean is rising at the rate of risingLevel per year). This is your final line of output.The output will be as follows (for a risingLevel" of 2.1) Years: 50, Rise: 105 For each of the above you need to output the number of years and the total rise in ocean levels for those years. This is all based on the value in risingLevel For example: ArisingLevel of 2.1 for 5 years would have the following output: Level: 2.1 Years: 5, Rise: 10.5 Years: Years: 50, Rise: 105 10, Rise: 21 Your output must have the same syntax and spacing as above

User Michalduda
by
5.2k points

1 Answer

3 votes

Answer:

Here is the C++ program:

#include <iostream> //to use input output functions

using namespace std; //to identify objects cin cout

int main(){ //start of main method

double risingLevel; //declares a double type variable to hold rising level

cin>>risingLevel; //reads the value of risingLevel from user

cout<<"Level: "<<risingLevel<<endl; //displays the rising level

cout << "Years: 5, Rise: " << risingLevel * 5<<endl; //displays the rise in ocean level over 5 years

cout << "Years: 10, Rise: " << risingLevel * 10<<endl; //displays the rise in ocean level over 10 years

cout << "Years: 50, Rise: " << risingLevel * 50<<endl; //displays the rise in ocean level over 50 years

}

Step-by-step explanation:

The program works as follows:

Lets say the user enters rising level 2.1 then,

risingLevel = 2.1

Now the first print (cout) statement :

cout<<"Level: "<<risingLevel<<endl; prints the value of risingLevel on output screen. So this statement displays:

Level: 2.1

Next, the program control moves to the statement:

cout << "Years: 5, Rise: " << risingLevel * 5<<endl;

which computes the rise in ocean levels over 5 years by formula:

risingLevel * 5 = 2.1 * 5 = 10.5

It then displays the computed value on output screen. So this statement displays:

Years: 5, Rise: 10.5 Next, the program control moves to the statement:

cout << "Years: 10, Rise: " << risingLevel * 10<<endl;

which computes the rise in ocean levels over 10 years by formula:

risingLevel * 10 = 2.1 * 10 = 21

It then displays the computed value on output screen. So this statement displays:

Years: 10, Rise: 21

Next, the program control moves to the statement:

cout << "Years: 50, Rise: " << risingLevel * 50<<endl;

which computes the rise in ocean levels over 50 years by formula:

risingLevel * 50 = 2.1 * 50 = 105

It then displays the computed value on output screen. So this statement displays:

Years: 50, Rise: 105 Hence the output of the entire program is:

Level: 2.1 Years: 5, Rise: 10.5 Years: 10, Rise: 21 Years: 50, Rise: 105

The screenshot of the program and its output is attached.

This program will calculate the rise in ocean levels over 5, 10, and 50 years, Part-example-1
User Rdiachenko
by
5.2k points