الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة فى برنامج لاظهار العمر بالسنة والشهر واليوم

بدأه smsmman في 16 أكتوبر 2012 · 5 رد · 840 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

كود برنامج لحساب العمر

  Console.Write("Enter Year of Birth : ");
            int myBirth = System.Convert.ToInt32(Console.ReadLine());
            int thisYear = System.DateTime.Now.Year;
            int age = thisYear - myBirth;
            Console.WriteLine("AGE = {0}", age.ToString());
            Console.Read();

انما ازاى اخلى البرنامج يظهر العمر بالسنة والشهر واليوم جربت نفس الطريقة مع اليوم والشهر ولكن عدد السنوات فقط هو من يخرج ..

وجزاكم الله خيرا

#2
DateTime birthdate = new DateTime(1981, 1, 7);
DateTime now = DateTime.Now;
int years = now.Year - birthdate.Year;
if (now.Month < birthdate.Month || (now.Month == birthdate.Month && now.Day < birthdate.Day))
  years--;
MessageBox.Show(years.ToString());

http://www.codeproject.com/Questions/178093/How-to-calculte-a-person-s-age-in-C-net

جميل أن يكون لك قلب أنت صاحبه ..

ولكن الأجمل أن يكون لك صاحب أنت قلبه ..

#3

جزاك الله خيرا اخي

ولكن انا اريدها على console

وعلى شاشة الout put

عندما اكتب تاريخ الميلاد ...

يكتب البرنامج العمر بعدد السنين والشهور والايام ....

وشكر جزيلا لحضرتك يفندم

#5
smsmman كتب:

جزاك الله خيرا اخي

ولكن انا اريدها على console

وعلى شاشة الout put

عندما اكتب تاريخ الميلاد ...

يكتب البرنامج العمر بعدد السنين والشهور والايام ....

وشكر جزيلا لحضرتك يفندم

أنا مبتدئ ولكن أعتقد الكود كالآتي:

Console.Write("Enter day of birth: ");
            int birthDay = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter Month of birth: ");
            int birthMonth = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter year of birth: ");
            int birthYear = Convert.ToInt32(Console.ReadLine());

            int nowDay = DateTime.Now.Day;
            int nowMonth = DateTime.Now.Month;
            int nowYear = DateTime.Now.Year;

            int oldDay = nowDay - birthDay;
            int oldMonth = nowMonth - birthMonth;
            int oldYear = nowYear - birthYear;

            Console.WriteLine("Your old is: {0} days, {1} months, {2} years.", oldDay, oldMonth, oldYear);

            Console.ReadKey();
#6

look to this code

Console.Write("birthdate whis format 'MM/dd/YYYY': ");
            DateTime dBirthDate = Convert.ToDateTime(Console.ReadLine());

            int nDay = Convert.ToDateTime(DateTime.Now - dBirthDate).Day;
            int nMonth = Convert.ToDateTime(DateTime.Now - dBirthDate).Month;
            int nYear = Convert.ToDateTime(DateTime.Now - dBirthDate).Year;

            Console.WriteLine("Your old is: {0} days, {1} months, {2} years.", nDay, nMonth, nYear);

            Console.ReadKey();

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…