Age- year

can anyone help me with this? please its urgent :((


cout << "Mr. "<< Name << " you were born on year " <<Age - Year;


I had problems on the last part of it. I have declared Year as 2011. And Age is based on what the user inputs. Can you help me?
cout << "Mr. "<< Name << " you were born on year " << Year - Age;
Below is a small example of what I think you're trying to accomplish. You could also get the year dynamically if you want from Windows API. Keep in mind this isn't very accurate, you would have to take into account down to the day if you want to truly be accurate.
1
2
3
4
5
6
7
8
9
10
11
12
#define CurrentYear 2011

int main()
{
	int iYear = 2011;

	std::cout << "Enter the year you were born." << std::endl;
	std::cin >> iYear;
	std::cout << "You are " << CurrentYear - iYear << "years old."

	return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
const char * const pszCurrentYear = 2011;

int main()
{
	int iYear = 2011;

	std::cout << "Enter the year you were born." << std::endl;
	std::cin >> iYear;
	std::cout << "You are " << CurrentYear - iYear << "years old."

	return 0;
}


-scott meyers
Last edited on
Topic archived. No new replies allowed.