Can’t see why code is not working when I’ve gone through it multiple times and it looks fine to me

I'm sure that these threads are not appropriated here and i'm not usually the one to post them, but in this odd scenario I've got some code that looks perfectly fine to me and really should work but it's not and I don't know where to turn.

So basically we have been asked to make a program where you can enter your name and date of birth and you should be able to calculate how many days old you are, sounds simple enough right?

So this is what I've done and to me it should work but it's clearly not so here we go

public partial class Form1 : Form {

 public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //Seting value for the months array String[] months = new string[] { "January", "February", "March", "April", "May", "June", "July", "Agust", "September", "October", "November", "December" }; //int for days int day = 1; while (day <= 31) { comboBoxDay.Items.Add(day); day = day + 1; } //Int ofr years int year = 1915; while (year <= 2000) { comboBoxYear.Items.Add(year); year = year + 1; } //Int for months int month = 0; while (month < 12) { comboBoxMonth.Items.Add(months[month]); month = month + 1; DateTime dateOfBirth = new DateTime(1981, 4, 20); } } private void button1Calculate_Click(object sender, EventArgs e) { DateTime today = DateTime.Today; int year = Convert.ToInt32(comboBoxYear.Text); int month = comboBoxMonth.SelectedIndex + 1; int day = Convert.ToInt32(comboBoxDay.Text); DateTime dateOfBirth = new DateTime(year, month, day); TimeSpan difference = today - dateOfBirth; textBoxCalculate.Text = textBoxName.Text + " " + "is" + " " + difference.TotalDays + " days old."; } private void textBoxCalculate_TextChanged(object sender, EventArgs e) { } private void timer1_Tick(object sender, EventArgs e) { string date = DateTime.Now.ToLongDateString(); string time = DateTime.Now.ToString("hh:MM:ss"); labelDateTime.Text = date + " " + time; } private void label1_Click(object sender, EventArgs e) { } private void comboBoxYear_SelectedIndexChanged(object sender, EventArgs e) { } private void textBoxName_TextChanged(object sender, EventArgs e) { } 

}

}

Sorry for the code past, can upload the program itself if needed and mods please delete this post if it's not the content you want

by Lymf via /r/csharp

Leave a Reply