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.Windows.Forms;
- namespace Hw_09_AileenChung2
- {
- public partial class Form1 : Form
- {
- static DateTime _randomDate;
- DateTime _guess;
- DateTime _previousGuess;
- public Form1()
- {
- InitializeComponent();
- }
- public static void RandomDateGenerator()
- {
- DateTime oneYearAgo = DateTime.Today.AddYears(-1);
- TimeSpan span = DateTime.Today - oneYearAgo;
- int numDays = span.Days;
- Random random = new Random();
- int randomInt = random.Next(numDays);
- _randomDate = oneYearAgo.AddDays(randomInt);
- }
- //this is what happens once someone confirms their guess
- private void btnGuess_Click(object sender, EventArgs e)
- {
- int tries = 0;
- tries++;
- if (dateGuess.Value == _randomDate)
- {
- lblStatus.Text = "You got it!";
- }
- else
- {
- lblStatus.Text = "Incorrect.";
- }
- }
- // this it he DateTimePicker that the guesser uses to guess the random date.
- //i want to only have them allowed to guess from today's date to a year ago from todays date.
- private void dateGuess_ValueChanged(object sender, EventArgs e)
- {
- //min date
- dateGuess.MinDate = DateTime.Today;
- //max date
- dateGuess.MaxDate = DateTime.Today.AddYears(-1);
- }
- }
- }
Add Comment
Please, Sign In to add comment