Oceans in millimeters program

I'm trying to write a program to export an ocean's level using 1.5 millimeters as the current variable. Then I need to show what the ocean's level will be at 5, 7, and 10 years.

I know I'm missing something. I need help please.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  // If the ocean’s level is currently rising at about 1.5 millimeters per year
// what will the ocean's level in 5 years
// what will the ocean's level in 7 years
// what will the ocean's level in 10 years

#include <iostream>

using namespace std;

int main()
{
	int millimeters; // variable current ocean's level

	millimeters = 1.5; // store 1.5 in the variable millimeters

	cout << "The ocean's level in 5 years." << endl;

	cout << "(1.5) * 5 = " << 1.5 * 5 << endl;

	cout << "The ocean's level in 7 years." << endl;

	cout << "(1.5) * 7 = " << 1.5 * 7 << endl;

	cout << "The ocean's level in 10 years." << endl;

	cout << "(1.5) * 10 = " << 1.5 * 10 << endl;

	return 0;
}
1.5 is a floating point number so use a float instead of an int when declaring millimeters. An int can only store integers (whole numbers).

1
2
float millimeters; // variable current ocean's level
millimeters = 1.5; // store 1.5 in the variable millimeters 


Then when you use your cout's you can use the following to supply the numbers to the terminal.

1
2
cout << "(1.5) * 5 = "<< millimeters * 5 << endl;
...


If your compiler is C11 compliant or later, you could possibly use std::to_string(millimeters) to remove all hard coded 1.5 values in your cout statements, and thus can change to any number of millimeters a year without having to change a lot of code.

Please forgive me for incorrect info. I was answering multiple posts while getting gas and got them crossed, the following code has been corrected.
Example:

 
cout << "(" << millimeters  << ") * 5 = " << millimeters * 5 << endl;
Last edited on
OK. Now I'm getting...

'Oceans.exe' (Win32): Loaded 'F:\C++ CLASS\Lab1\Oceans\Debug\Oceans.exe'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\WRusr.dll'. Cannot find or open the PDB file.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\psapi.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Symbols loaded.
'Oceans.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ucrtbased.dll'
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\msvcp140d.dll'
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\urlmon.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wininet.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Symbols loaded.
'Oceans.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\combase.dll'
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\iertutil.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32full.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\advapi32.dll'
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\windows.storage.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp_win.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\win32u.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\powrprof.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\fltLib.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\secur32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msimg32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Symbols loaded.
The thread 0x2e78 has exited with code 0 (0x0).
The thread 0xe48 has exited with code 0 (0x0).
The thread 0x2f58 has exited with code 0 (0x0).
The thread 0x2ffc has exited with code 0 (0x0).
The program '[4664] Oceans.exe' has exited with code 0 (0x0).

while running the following code...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

int main()
{
	float millimeters; // float current ocean's level

	millimeters = 1.5; // store 1.5 in the variable millimeters

	cout << "The ocean's level in 5 years." << endl;

	cout << "(1.5) * 5 = " << millimeters * 5 << endl;

	cout << "The ocean's level in 7 years." << endl;

	cout << "(1.5) * 7 = " << millimeters * 7 << endl;

	cout << "The ocean's level in 10 years." << endl;

	cout << "(1.5) * 10 = " << millimeters * 10 << endl;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    const double mms_per_year = 1.5 ;

    for( const int num_years : { 5, 7, 10 } )
    {
        const double increase = mms_per_year * num_years ;
        std::cout << "the ocean's level has gone up by " << increase
                  << " millimeters in " << num_years << " years\n" ;
    }

    std::cout << "\npress enter to quit program... " ;
    std::cin.get() ; // keep the console open till user presses enter
}
It looks like your program executed faster than you were able to read the output. It looks like you may be using Visual Studio, in which case try pressing ctrl + F5.

JLBorges code of
1
2
std::cout << "\npress enter to quit program... " ;
std::cin.get() ; // keep the console open till user presses enter 


Is another way to keep the command window open until you're ready to exit.
Last edited on
I'm using Visual Studio.

This what I have now but still get errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

using namespace std;

int main()
{

	double num1, num2, num3, num4;

	cout << "The ocean's level current level." << endl;

	num1 = 1.5;
	cout << "num1 = " << num1 << endl;

	cout << "The ocean's level in 5 years." << endl;

	num2 = num1 * 5;
	cout << "num2 = " << num2 << endl;

	cout << "The ocean's level in 7 years." << endl;

	num3 = num1 * 7;
	cout << "num3 = " << num3 << endl;

	cout << "The ocean's level in 10 years." << endl;

	num4 = num1 * 10;
	cout << "num4 = " << num4 << endl;

}
The messages
Oceans.exe' (Win32): Loaded 'F:\C++ CLASS\Lab1\Oceans\Debug\Oceans.exe'. Symbols loaded.
'Oceans.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
... 

are not errors.

To keep the console open, add these two lines right at the end of main, and build and run the program again.
1
2
cout << "\npress enter to quit program... " ;
cin.get() ; // keep the console open till user presses enter 

Here is the final product. Thanks for the help.

// If the ocean’s level is currently rising at about 1.5 millimeters per year
// what will the ocean's level in 5 years
// what will the ocean's level in 7 years
// what will the ocean's level in 10 years

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>

using namespace std;

int main()
{

	double num1, num2, num3, num4;

	cout << "The ocean's level current level." << endl;

	num1 = 1.5;
	cout << "num1 = " << num1 << endl;

	cout << "The ocean's level in 5 years." << endl;

	num2 = num1 * 5;
	cout << "num2 = " << num2 << endl;

	cout << "The ocean's level in 7 years." << endl;

	num3 = num1 * 7;
	cout << "num3 = " << num3 << endl;

	cout << "The ocean's level in 10 years." << endl;

	num4 = num1 * 10;
	cout << "num4 = " << num4 << endl;

	cout << "\npress enter to quit program... ";
	cin.get(); // keep the console open till user presses enter 


}
Topic archived. No new replies allowed.