Guest User

Untitled

a guest
Jun 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Testing
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.WriteLine("Please input time to countdown: ");
  13.             string input = Console.ReadLine(); //getting input form the user
  14.  
  15.             int inputInt = 0;
  16.             int.TryParse(input, out inputInt); //parse the string into an int
  17.  
  18.             DateTime old = DateTime.Now; //get current time
  19.  
  20.             Console.WriteLine(inputInt); //output the number the user started with
  21.             inputInt--; //decrement the counter
  22.  
  23.             for (; inputInt >= 0;) //loop till the counter is 0
  24.             {
  25.                 //the only tricky bit, get the current time and subtract the time you started at
  26.                 //check if this difference is 1 second or more
  27.                 if (DateTime.Now.Subtract(old) >= new TimeSpan(0, 0, 1))
  28.                 {
  29.                     //if it is 1 second or more
  30.                     Console.WriteLine(inputInt); //write the next number
  31.                     inputInt--; //decrement counter
  32.                     old = DateTime.Now; //update the timer
  33.                 }
  34.             }
  35.  
  36.             Console.WriteLine("End"); //print end
  37.         }
  38.     }
  39. }
Add Comment
Please, Sign In to add comment