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 button at the bottom of the screen. Sample program execution: My Current Age is 29. I will be 65 in 2050.
I am not sure how to add my output.
This is what I have so far:
// This program calculates your age in the year 2050.
// Input: None // Output: Your current age followed by your age in 2050
#include using namespace std;
int main()
'currentYear'; /2019/.match('currentYear') =>MatchData "2019"
'myCurrentAge'; /20/.match('myCurrentAge') => > "My Current Age is" count >> 'myCurrentAge'
int 'currentYear'
'currentYear'= 2019;
count >> "Current Year"
count >> 'currentYear'
int 'myNewAge'
'myNewAge'= 51;
count >> "I will be"
count >> 'myNewAge'
51 = 20 + (2050 - 2019);
cout << "My Current Age is " << 20 << endl;
cout << "I will be " << 51 << " in 2050." << endl;
return 0; }
The answer to this question is as follows:
#include <iostream>
using namespace std;
int main() {
int currentYear=2019;//declaring the current year
int myCurrentAge=29;//declaring the current age
int myNewAge=myCurrentAge+(2050-currentYear);//declaring the new
age with logic
//displaying the cureent age and new age
cout << "My Current Age is " <<myCurrentAge <<
endl;
cout << "I will be " << myNewAge << " in 2050."
<< endl;
}
Get Answers For Free
Most questions answered within 1 hours.