Sunday, March 7, 2010

age counter in C++

here is my simple age counter program, the concept still same likemy previous code's



#include <iostream>
//age counter program

using namespace std;

int main()
{
//variable declaration
char name[32];
int bday, bmonth, byear;
int tday, tmonth, tyear;
int bdate, tdate;
int day, month, year;

//input process
cout<<"who are you? ";
cin>> name;

//input birth
cout<<"input birth day ";
cin>> bday;
cout<<"input birth month ";
cin>> bmonth;
cout<<"input birth year ";
cin>> byear;

//input recent
cout<<"input recent day ";
cin>> tday;
cout<<"input recent month ";
cin>> tmonth;
cout<<"input recent year ";
cin>> tyear;
cin.ignore();

//algorythm processing 
bdate=bday+(bmonth*30)+(byear*365);
tdate=tday+(tmonth*30)+(tyear*365);

//result processing
day=(tdate-bdate)%365%30;
month=(tdate-bdate)%365/30;
year=(tdate-bdate)/365;

//result
cout<< name;
cout<< ","<< day<<","<< month<< ","<<year;

//commentation
if (year<=5){
cout<<" you're still baby";
}
else if (year<=17){
cout<<" you're still young";
}
else if (year<=40){
cout<<" you're an adult";
}
else if (year<=99){
cout<<" you're old enough";
}
else {
cout<<" are you serious?";
}

cin.get();
return 1;
}


No comments:

Post a Comment