Page 1 of 1

NEED HELP! Write a program called "age.cpp" that asks for the user’s name and year of birth, greets the user by name, an

Posted: Sat May 14, 2022 3:30 pm
by answerhappygod
NEED HELP!
Write a program called "age.cpp" that asks for the user’s name
and year of birth, greets the user by name, and declares the user’s
age in years. Pointer tm in should be use to determine the age of
user through built in functions time() and locatetime() in
ctime.
/* localtime example */ #include #include // time_t, struct tm,
time, localtime, asctime using namespace std; int main () { time_t
rawtime; struct tm * timeinfo; time (&rawtime); timeinfo =
localtime(&rawtime); cout << "\nCurrent local time and
date: " << asctime(timeinfo); cout << "\nCurrent year
from struct tm: " << timeinfo->tm_year + 1900; return 0;
}
Users are assumed to be born between the years 1800 and 2099,
and should enter the year of birth in one of the three formats
18XX, 19XX, or 20XX. A typical output should be “Hello Alexander
Jones, you are 43 years old.”
Tell me your name: Alexander Jones What year were you born?
(Format 18XX, 19XX or 20XX): 1978 Hello, Alexander Jones You are 43
years old.