برنامج لحساب العمر بالأيام و الأشهر و السنوات باستعمال لغة البرمجة C#.net
using System;
namespace ageCalc
{
class Program
{
public static void Main(
string[] args)
{
// حساب تاريخ اليوم
// السنة الحالية
int currentYear = DateTime.Now.Year;
// الشهر الحالي
int currentMonth = DateTime.Now.Month;
// اليوم الحلي
int currentDay = DateTime.Now.Day;
// ادخل تاريخ الميلاد باليوم و الشهر و السنة
Console.
WriteLine(
"Enter your birth:");
Console.
WriteLine(
"Year:");
int birthYear =
int.
Parse(Console.
ReadLine());
Console.
WriteLine(
"month:");
int birthMonth =
int.
Parse(Console.
ReadLine());
Console.
WriteLine(
"day:");
int birthDay =
int.
Parse(Console.
ReadLine());
//حساب العمر
int age;
if (currentMonth < birthMonth) age = currentYear - birthYear -
1;
else age = currentYear - birthYear;
Console.
WriteLine(
"Your age is : {0}",age);
Console.
WriteLine(
"++-----------------------------------------------++");
//حساب العمر بالأشهر
int monthAge =
0;
if (currentMonth < birthMonth) {
monthAge =
12 * age + (
11 - (birthMonth - currentMonth));
}
else {
monthAge =
12 * age + (currentMonth - birthMonth);
}
Console.
WriteLine(
"Your age in month is : {0}",monthAge);
Console.
WriteLine(
"++-----------------------------------------------++");
//حساب العمر بالأيام
int dayAge = monthAge *
30;
Console.
WriteLine(
"Your age in day is : {0}",dayAge);
Console.
WriteLine(
"-----------------------------------------------");
Console.
WriteLine(
"you have {0} years , {1} months and {2} days :)",age,monthAge,dayAge);
Console.
WriteLine(
"-----------------------------------------------");
Console.
WriteLine(
"Programed By Ahmed to www.gate4tech.com");
Console.
WriteLine(
"-----------------------------------------------");
Console.
Write(
"Press any key to Exit . . . ");
Console.
ReadKey(
true);
}
}
}