Guest User

Untitled

a guest
Feb 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace AgeCalculator
  8. {
  9.  
  10. class AgeCalculator
  11. {
  12.  
  13. static void Main(string[] args)
  14. {
  15. int byear, bmonth, bday,cyear,cmonth,cday;
  16. Console.WriteLine("Enter your date of birth in yy_mm_dd format.");
  17.  
  18. byear = Convert.ToInt32(Console.ReadLine());
  19. bmonth = Convert.ToInt32(Console.ReadLine());
  20. bday = Convert.ToInt32(Console.ReadLine());
  21.  
  22. Console.WriteLine("Enter current date in same format.");
  23. cyear = Convert.ToInt32(Console.ReadLine());
  24. cmonth = Convert.ToInt32(Console.ReadLine());
  25. cday = Convert.ToInt32(Console.ReadLine());
  26.  
  27. if (bday >= 1 && bday <= 31 && bmonth <= 12 && bmonth >= 1)
  28. {
  29. Console.WriteLine("Your date of birth is {0}/{1:D2}/{2:D2}",
  30. byear, bmonth, bday);
  31. getAge(byear, bmonth, bday, cyear, cmonth, cday);
  32.  
  33. }
  34. else { Console.WriteLine("Please enter a valid day or month."); }
  35.  
  36. Console.ReadLine();
  37. }
  38.  
  39. public static void getAge(int by,int bm,int bd,int cy,int cm,int cd){
  40. int[] Months = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  41. int totaldays = 0;
  42. int totalmonth = 0;
  43. for (int i = 0; i < Months.Length; i++)
  44. {
  45. if (cm == i)
  46. {
  47.  
  48.  
  49. if (bd > cd)
  50. {
  51. cm = cm - 1;
  52. cd = cd + Months[i];
  53. Console.WriteLine("current days " + cd);
  54.  
  55. }
  56. else { totaldays = cd - bd; }
  57.  
  58.  
  59. }
  60. }
  61.  
  62. if (bm > cm)
  63. {
  64. cy = cy - 1;
  65. cm = cm + 12;
  66. totalmonth = cm - bm;
  67. }
  68. else
  69. {
  70. totalmonth = cm - bm;
  71. }
  72.  
  73. int totalyears = cy - by;
  74.  
  75. Console.WriteLine("your age is {0:D2}years {1:D2} months and {2:D2}
  76. days", totalyears, totalmonth, totaldays);
  77. }
  78. }
  79. }
  80. //cy=current year
  81. //by=birth year
  82. //and same for other parameters og getage method
Add Comment
Please, Sign In to add comment