Make a report to explain each step in this Dev C++ prog. including introduction,steps of the program , discussion , conclusion and flow chart :
#include
using namespace std;
int main ()
{
/* Program to calculate Age */
cout << “nntt Basili’s Age Calculator nn”;
int yearnow,monthnow,yearthen,monththen,age1,age2; /* age1 to calculate years and age2 to calculate months */
/* year now for the current year and yearthen for the year of birth */
cout<<“Enter current year and then current month n (Eg.2017,enter,8,enter): n”;
cin>>yearnow;
cin>>monthnow;
cout<<“Enter your birthyear and then month of birth n (Eg.1996,enter,12,enter) : “;
cin>>yearthen;
cin>>monththen;
while(monththen <= 0 || monththen > 12 || monththen <= 0 || monththen > 12) /* If the user entered invalid value for month which is 1 to 12 The program will be restarted */
{
cout <
cout << “1 to 12 are valid values.” << endl;
cout << “Enter a valid value: “;
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;
main();
}
while (yearthen>yearnow ) /* If the user entered invalid value for year which means that the year of birth is bigger than the current year , The program will be restarted */
{
cout <
cout << “Just wait a few days, or enter a valid current year or birthyear : “;
cout << endl << “The program will be restarted so you can enter your “;
cout << “data again.” << endl << endl;
main();
}
if (monththen>monthnow)
{
age1=yearnow-yearthen-1; /* The result of (yearnow-yearthen) -1 becouse we still in the current year which the user entered in the program */
age2=(12-monththen)+monthnow;
/* (12 – month of birth) to count how many months the user have lived in the year of birth , then (+ the current month) which you have lived in current year */
}
else
{
age1=yearnow-yearthen; /* The result of (yearnow-yearthen) -1 becouse we still in the current year which the user entered in the program */
age2=12-monththen;
}
cout<<“nn you are “<
system (“pause>>void”);
}
Expert Answer
INTRODUCTION:
The Age Calculator program will take input from user which is current date and date of birth of user. The program will validate all the inputs and if the inputs are valid, it will print the current age. The logic is to simply compare the current date and birthdate, and print the difference.
STEPS OF PROGRAM:
1. Declare required variables yearnow, monthnow, yearthen, monththen, age1, age2. Take current year and then current month from user.
2. Take birthyear and then month of birth from user.
3. Check by using while loop, if the user entered invalid value for month which is 1 to 12 , if not program will be restarted .
4. Check by using while loop if the user entered invalid value for year which means that the year of birth is bigger than the current year , if not then program will be restarted .
5. Check if entered birth month is greater than current month , if so then the resulting number of years of (yearnow – yearthen) -1.
If not then age2=(12-monththen) + monthnow to count how many months the user has lived in the year of birth, then (+ the current month) which you have lived in current year.
DISCUSSION:
The program should take only the birth date and not the current date. The program should use the system date.
CONCLUSION:
The program gives the desired result and the program does all the validation with proper feedback to user to understand and feed the correct input.
FLOWCHART: