Declaring and Initializing C++ Variables
Summary
In this lab, you declare and initialize variables in a C++ program. The program, which is saved in a file named NewAge.cpp, calculates your age in the year 2050.
Instructions
- Declare an integer variable named myNewAge.
- Declare and initialize an integer variable named myCurrentAge. Initialize this variable with your current age.
- Declare and initialize an integer variable named currentYear. Initialize this variable with the value of the current year. Use four digits for the year.
- Execute the program by clicking the "Run Code" button at the bottom of the screen.
Sample program execution:
My Current Age is 29.
I will be 65 in 2050.