How to calculate the age of a person?
例如,我需要计算从1996-11-03(yy/mm/dd)到现在的过去时间。我需要在Windows Visual C++中在Windows窗体应用程序中完成它。用户将在3个不同的文本框中输入年、月、日。有什么想法吗?
这将帮助你幸运。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include<iostream> using namespace std; int main() { system("TITLE how old are you?"); system("color f3"); int yearnow,yearthen,monthnow,monththen,age1,age2; cout<<"\t\t\tEnter the current year and month \t\t\t(eg. 1997, enter, 7, enter): "; cin>>yearnow; cin>>monthnow; cout<<"Enter your birthyear and month: "; cin>>yearthen; cin>>monththen; if(monththen >12 || monththen<1) return 1; if(monththen > monthnow){ age1=yearnow-yearthen-1; age2=(12-monththen) + monthnow; }else{ age1=yearnow-yearthen; age2=12-monththen; } cout<<" \t\t\tYou are"<<age1<<" year and"<<age2<<" moth old"; system("pause>>void"); } |