berikut adalah program penghitung umur sederhana dengan C++. pertama - tama, program akan menanyakan nama pengguna. lalumeminta input dari pengguna. dan yang terakhir, memberi komentar










#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;
}


Diposting oleh Unknown Senin, 08 Maret 2010

Subscribe here