| | |
Your exact age
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 15
Reputation:
Solved Threads: 0
this program contains everything even leap year:
i am a beginner in cpp (we have this in school so i am learning this age 15 )
<< moderator edit: added [code][/code] tags >>
i am a beginner in cpp (we have this in school so i am learning this age 15 )
C++ Syntax (Toggle Plain Text)
# include<iostream.h> # include<conio.h> void main (void) { clrscr(); int years1, months1, days1; int monthdays1[12] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; int startday; int years2, months2, days2; int endday; int leapdays1, leapdays2; int oldyears, agebalance, balancedays, oldmonths, olddays, i; int const BASEYEAR=1900; int const BASEMONTH=12; int const BASEDAY=31; //Input birth date cout<<"Enter the date you were born(dd mm yyyy):\t"; cin>>days1>>months1>>years1; cout<<endl; //error if (years1<BASEYEAR) { cout<<"The value of year is below 1900 Press any key to continue"; getch(); return; } if (months1>BASEMONTH) { cout<<"The value of months is above 12 Press any key to continue"; getch(); return; } if (days1>BASEDAY) { cout<<"The value of days is above 31 Press any key to continue"; getch(); return; } //input todays date cout<<"Enter the date today(dd mm yyyy):\t"; cin>>days2>>months2>>years2; cout<<endl; //error if (years2<BASEYEAR) { cout<<"The value of years is below 1900 Press any key to continue"; getch(); return; } if (months2>BASEMONTH) { cout<<"The value of months is above 12 Press any key to continue"; getch(); return; } if (days2>BASEDAY) { cout<<"The value of days is above 31 Press any key to continue"; getch(); return; } //calculation years1=years1-1; months1=months1-1; days1=days1; leapdays1=years1/4; //leapyear is a multiple for 4 if((months1>=2) && ((years1+1)%4==0)) leapdays1++; if(years1>1999) leapdays1--; //2000 is no leapyear startday=(years1*365)+monthdays1[months1-1]+days1+leapdays1; years2=years2-1; months2=months2-1; days2=days2; leapdays2=years2/4; //leapyear is a multiple for 4 if((months2>=2) && ((years2+1)%4==0)) leapdays2++; if(years2>1999) leapdays2--; //2000 is no leapyear endday=(years2*365)+monthdays1[months2-1]+days2+leapdays2; agebalance=endday-startday; oldyears=agebalance/365; balancedays=agebalance%365; i=0; while (balancedays> monthdays1[i]) { i++; } oldmonths=i; olddays=balancedays-monthdays1[oldmonths-1]; //output cout<<"Your age is "<<oldyears<<" years, "<<oldmonths<<" months, "; cout<<olddays<<" days"<<endl; getch(); }
•
•
•
•
Originally Posted by cpp noob
C++ Syntax (Toggle Plain Text)
if(years1>1999) leapdays1--; //2000 is no leapyear
![]() |
Similar Threads
- fstream Tutorial (C++)
- age calculator (Computer Science)
- 'New' PC with Win95, tips? (Windows 95 / 98 / Me)
- Evolution: Science vs. Religion (Geeks' Lounge)
- I've made some code to reject age ranges, but cant get it working (Java)
Other Threads in the C++ Forum
- Previous Thread: help with saving data to and reading from file
- Next Thread: Visual Studio 6.0 or Visual Studio .Net 2003
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






