write a program that prompts the user, within a while loop, for a birth month an
ID: 3624329 • Letter: W
Question
write a program that prompts the user, within a while loop, for a birth month and birth year,and than calculate and display the corresponding age. Note:do the initial prompt outside the loop.use the following formula to calculate age:
age=curyear-birthyear+(curmonth-birthmonth)/12
check for user input error in a do while loop. if the birth year or month is not valid then prompt the user again.
End the loop when the user enters 0 for birth year, and 0 for the birth month.
Explanation / Answer
Here it is, please rate! #include using namespace std; int main() { int currYear, currMonth, birthYear=1, birthMonth=1, age; cout > currYear; cout > currMonth; while(birthYear != 0 && birthMonth != 0) { do { cout > birthYear; }while(birthYear < 0); do { cout > birthMonth; }while(birthMonth < 0); if(birthYear > 0 && birthMonth > 0) { age = currYear-birthYear + (currMonth-birthMonth)/12; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.