Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace AgeCalculator
- {
- class AgeCalculator
- {
- static void Main(string[] args)
- {
- int byear, bmonth, bday,cyear,cmonth,cday;
- Console.WriteLine("Enter your date of birth in yy_mm_dd format.");
- byear = Convert.ToInt32(Console.ReadLine());
- bmonth = Convert.ToInt32(Console.ReadLine());
- bday = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Enter current date in same format.");
- cyear = Convert.ToInt32(Console.ReadLine());
- cmonth = Convert.ToInt32(Console.ReadLine());
- cday = Convert.ToInt32(Console.ReadLine());
- if (bday >= 1 && bday <= 31 && bmonth <= 12 && bmonth >= 1)
- {
- Console.WriteLine("Your date of birth is {0}/{1:D2}/{2:D2}",
- byear, bmonth, bday);
- getAge(byear, bmonth, bday, cyear, cmonth, cday);
- }
- else { Console.WriteLine("Please enter a valid day or month."); }
- Console.ReadLine();
- }
- public static void getAge(int by,int bm,int bd,int cy,int cm,int cd){
- int[] Months = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- int totaldays = 0;
- int totalmonth = 0;
- for (int i = 0; i < Months.Length; i++)
- {
- if (cm == i)
- {
- if (bd > cd)
- {
- cm = cm - 1;
- cd = cd + Months[i];
- Console.WriteLine("current days " + cd);
- }
- else { totaldays = cd - bd; }
- }
- }
- if (bm > cm)
- {
- cy = cy - 1;
- cm = cm + 12;
- totalmonth = cm - bm;
- }
- else
- {
- totalmonth = cm - bm;
- }
- int totalyears = cy - by;
- Console.WriteLine("your age is {0:D2}years {1:D2} months and {2:D2}
- days", totalyears, totalmonth, totaldays);
- }
- }
- }
- //cy=current year
- //by=birth year
- //and same for other parameters og getage method
Add Comment
Please, Sign In to add comment