Write a Program that asks the user for her birthday. If the user entered a valid date (check to make sure and
keep asking if the user did not enter a date), display a message box telling the user how many years until she
reaches the retirement age of 65. If the user is older than 65, congratulate her on a long life!
keep asking if the user did not enter a date), display a message box telling the user how many years until she
reaches the retirement age of 65. If the user is older than 65, congratulate her on a long life!
Program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Question4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DateTime D;
string CombinedDate = String.Format("{0}-{1}-{2}", textBox1.Text, textBox2.Text, textBox3.Text);
if (DateTime.TryParseExact(CombinedDate, "d-M-yyyy", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out D))
{
int age = Convert.ToInt32(textBox3.Text);
age = 2015 - age;
MessageBox.Show("Your Age Is " + age);
if (age >= 65)
{
MessageBox.Show("We Congratulate you on your long life");
}
else
{
age = (-age) + 65;
MessageBox.Show("You Have Got "+age+" Years For Your Retirement");
}
}
else
{
MessageBox.Show("invalid Date Entered");
}
}
}
}
Post A Comment:
0 comments: