Написать функцию, проверяющую, предшествует ли время t1 времени t2 (в рамках суток) - C#
Формулировка задачи:
Составные типы данных: структуры
Время можно представить с помощью часов,минут и секунд. Написать функцию проверка(t1,t2),проверяющую,предшествует ли время t1 времени t2(в рамках суток)
Поочередно вводятся два времени и отображаются в datagridview. При нажатии на отдельную кнопку проверить.
struct Time
{
public int hours;
public int minutes;
public int seconds;
}Решение задачи: «Написать функцию, проверяющую, предшествует ли время t1 времени t2 (в рамках суток)»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication
{
class aragog
{
struct Time
{
public int hours;
public int minutes;
public int seconds;
}
private static void initTime(ref Time timer)
{
int checkInputDate;
do
{
Console.Write(" hours = "); checkInputDate = int.Parse(Console.ReadLine());
}
while ((!((0 <= checkInputDate) && (checkInputDate <= 23))));
timer.hours = checkInputDate;
do
{
Console.Write(" minutes = "); checkInputDate = int.Parse(Console.ReadLine());
}
while ((!((0 <= checkInputDate) && (checkInputDate <= 59))));
timer.minutes = checkInputDate;
do
{
Console.Write(" second = "); checkInputDate = int.Parse(Console.ReadLine());
}
while ((!((0 <= checkInputDate) && (checkInputDate <= 59))));
timer.seconds = checkInputDate;
}
private static void compareTime(ref Time t1,ref Time t2)
{
/*1*/
//if (t1.hours > t1.hours) { Console.WriteLine("Timer 1(h) > Timer 2(h)"); }
//else
//{
// if (t1.hours < t1.hours) { Console.WriteLine("Timer 1(h) < Timer 2(h)"); }
// else
// {
// if (t1.minutes > t2.minutes) { Console.WriteLine("Timer 1(m) > Timer 2(m)"); }
// else
// {
// if (t1.minutes < t2.minutes) { Console.WriteLine("Timer 1(m) < Timer 2(m)"); }
// else
// {
// if (t1.seconds > t2.seconds) { Console.WriteLine("Timer 1(s) > Timer 2(s)"); }
// else
// {
// if (t1.seconds < t2.seconds) { Console.WriteLine("Timer 1(s) < Timer 2(s)"); }
// else
// {
// Console.WriteLine("Timer 1 == Timer 2");
// }
// }
// }
// }
// }
//}
/*2*/
//if (((t1.hours - t2.hours) == 0) && ((t1.minutes - t2.minutes) == 0) && ((t1.seconds - t2.seconds) == 0))
//{
// Console.WriteLine("Timer 1 == Timer 2");
//}
//else
//{
// Console.WriteLine("Timer 1 != Timer 2");
//}
/*3*/
if (((t1.hours - t2.hours) == 0) && ((t1.minutes - t2.minutes) == 0) && ((t1.seconds - t2.seconds) == 0))
{
Console.WriteLine("Timer 1 == Timer 2");
}
else
{
if (((t1.hours - t2.hours) > 0) || ((t1.minutes - t2.minutes) > 0) || ((t1.seconds - t2.seconds) > 0))
{
Console.WriteLine("Timer 1 > Timer 2");
}
else
{
if (((t1.hours - t2.hours) < 0) || ((t1.minutes - t2.minutes) < 0) || ((t1.seconds - t2.seconds) < 0))
{
Console.WriteLine("Timer 1 < Timer 2");
}
}
}
}
static void Main(string[] args)
{
Time t1 = new Time();
Time t2 = new Time();
Console.WriteLine("Time 1"); initTime(ref t1);
Console.WriteLine("Time 2"); initTime(ref t2);
compareTime(ref t1,ref t2);
Console.ReadKey();
}
}
}