T
T
T0rent02022-03-03 11:41:40
Command line
T0rent0, 2022-03-03 11:41:40

How to create a timer in c#?

how to make a timer in c# let's say the user enters the number of hours, minutes, seconds after that each time the line is updated and shows how much time is left type "You have (int hours) hours (int minutes) minutes (int seconds) seconds" and at the end of the timer, the line "Time out" was displayed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
T0rent0, 2022-03-03
@T0rent0

using System;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Timer();
}
static void print(string text)
{
int i = 0;
while (i < text.Length)
{
Console.Write(text[i]);
Thread.Sleep(50);
i++;
}
Console.Write("\n\n");
}
static void Timer()
{
print("Enter number of minutes");
int minutes = Convert.ToInt32(Console.ReadLine());
print("Enter number of hours");
int Hours = Convert.ToInt32(Console.ReadLine());
print("Enter number of seconds");
int seconds = Convert.ToInt32(Console.ReadLine());
seconds = seconds - 1;
if (seconds == -1)
{
minuts = minuts - 1;
seconds = 59;
}
if ( minutes == -1)
{
Hours = Hours - 1;
minutes = 59;
}
if(Hours == -1)
{
print("Time is up");
}
print("Remaining " + Hours + " hours " + minutes + " Minutes " + seconds + " Seconds ");
}
}
}
while there is only this but it shows the time only once how to fix it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question