Question #37734

wap to input age of a person and print it in days.

Expert's answer

Answer on Question#37734- Programming, C#

1. Wap to input age of a person and print it in days.

Solution.


/// Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
/// Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime dtNow = DateTime.Now;
                int Day = dtNow.Day - Convert.ToInt32(textBox1.Text);
                int Month = dtNow.Month - Convert.ToInt32(textBox2.Text);
                int Year = dtNow.Year - Convert.ToInt32(textBox3.Text);
                DateTime dt = new DateTime(Year, Month, Day);
                textBox4.Text = Convert.ToString(DateTime.Now.Subtract(dt.Date).Days);
            }
            catch
            {
                MessageBox.Show("Correctly enter data!");
            }
        }
        private void textBox1_Enter(object sender, EventArgs e)
        {
            textBox1.Clear();
        }
        private void textBox2_Enter(object sender, EventArgs e)
        {
            textBox2.Clear();
        }
        private void textBox3_Enter(object sender, EventArgs e)
        {
            textBox3.Clear();
        }
    }
}


You can also run the file in the attached file .exe

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS