Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace pocitadlo
- {
- public partial class Form1 : Form
- {
- int day; int month; int year; int aday; int amonth; int ayear;
- byte[] months = new byte[13] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- public Form1()
- {
- InitializeComponent();
- }
- private void checkDatum_CheckedChanged(object sender, EventArgs e)
- {
- if (checkDatum.Checked == false)
- {
- txtADay.Visible = true;
- txtAMonth.Visible = true;
- txtAYear.Visible = true;
- labelDatum.Visible = true;
- btnSend.Location = new Point(265, 104);
- }
- else
- {
- txtADay.Visible = false;
- txtAMonth.Visible = false;
- txtAYear.Visible = false;
- labelDatum.Visible = false;
- btnSend.Location = new Point(162, 104);
- }
- }
- private void btnSend_Click(object sender, EventArgs e)
- {
- int s1 = 0; int s2 = 0; int v = 0; int age = 0;
- if (checkDatum.Checked == true)
- {
- aday = DateTime.Now.Day;
- amonth = DateTime.Now.Month;
- ayear = DateTime.Now.Year;
- }
- else
- {
- aday = int.Parse(txtADay.Text);
- amonth = int.Parse(txtAMonth.Text);
- ayear = int.Parse(txtAYear.Text);
- }
- day = int.Parse(txtDay.Text);
- month = int.Parse(txtMonth.Text);
- year = int.Parse(txtYear.Text);
- if (year % 4 == 0 && ayear % 4 == 0)
- months[2] = 29;
- else months[2] = 28;
- for (int i = 1; i <= month; i++)
- s1 += months[i];
- for (int i = 1; i <= amonth; i++)
- s2 += months[i];
- v = (s1 + day) - (s2 + aday);
- if (day == aday && month == amonth)
- {
- age = ayear - year;
- if (year % 4 == 0 && ayear % 4 == 0)
- v = v + 366;
- else v = v + 365;
- }
- else age = (ayear - year) - 1;
- if (v < 0)
- {
- age++;
- if (year % 4 == 0 && ayear % 4 == 0)
- v = v + 366;
- else v = v + 365;
- }
- Output1.Text = "Máš "+ age +" rokov";
- Output2.Text = "Za "+ v + " dní budeš mať narodeniny";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment