Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Testing
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Please input time to countdown: ");
- string input = Console.ReadLine(); //getting input form the user
- int inputInt = 0;
- int.TryParse(input, out inputInt); //parse the string into an int
- DateTime old = DateTime.Now; //get current time
- Console.WriteLine(inputInt); //output the number the user started with
- inputInt--; //decrement the counter
- for (; inputInt >= 0;) //loop till the counter is 0
- {
- //the only tricky bit, get the current time and subtract the time you started at
- //check if this difference is 1 second or more
- if (DateTime.Now.Subtract(old) >= new TimeSpan(0, 0, 1))
- {
- //if it is 1 second or more
- Console.WriteLine(inputInt); //write the next number
- inputInt--; //decrement counter
- old = DateTime.Now; //update the timer
- }
- }
- Console.WriteLine("End"); //print end
- }
- }
- }
Add Comment
Please, Sign In to add comment