1.write a program that prompts the user, within a while loop, for a birth month
ID: 3620349 • Letter: 1
Question
1.write a program that prompts the user, within a while loop, for a birth month and birth year,and then calculates and displays the corresponding age.Note:do the initial prompt outside the loop.use the following formula to calculate the age:
age=currentyear-birthyear+(currentmonth-birthmonth)/12
2.check for user input error in a do while loop.if the birth year or month is not valid then prompt the user again.
3.end the loop when the user enters 0 for the birthyear, and 0 for the birth month.
Explanation / Answer
#include #include #include struct Dateinfo() { int cyr, cmnth; cyr= _startYear() + info.tm_year; cmnth=i nfo.tm_mon + 1; } void main() { int bmnth=0, byr=0; float age; coutDateinfo.cyr||(byr = Dateinfo.cyr && bmnth !> Date)) { while(bmnth!== 0 && byr!== 0) { coutbmnth; coutbyr; age= Dateinfo.cyr- byr + (Dateinfo.cmnth - bmnth)/12; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.