C
C
CatalystX2018-11-04 18:43:51
C++ / C#
CatalystX, 2018-11-04 18:43:51

What is your evaluation of the simple time converter code?

I'm learning C. Wrote a simple time converter. Rate it please

//Конвертер временных значений
#include<stdio.h>
#define A_PER_B 60 //константа значения
int main(void)
{
  int sec, min, hor, left, input;//объявление переменных
  printf("Welcome in time converter!\n");
  printf("For continue press any key and 0 for exit\n");
  scanf_s("%d", &input);
    while (input != 0)
    {
      printf("Choose mode\n");
      printf("1.Sec to min\n2.Min to hor\n3.Hor to min\n4.Min to sec\n5.Exit\n");
      scanf_s("%d", &input);//выбор режима конвертера 
      switch (input)
      {
      case 1:
        printf("Enter quantity sec\n");
        scanf_s("%d", &sec);
        while (sec > 0)
        {
          min = sec / A_PER_B;//операция нахождения минут 
          left = sec%A_PER_B;//остаток секунд
          printf("%d sec is %d min and %d sec\n", sec, min, left);
          printf("Enter next value(Enter 0 for exit!)\n");
          scanf_s("%d", &sec);//ввод нового значения, либо выход из цикла
        }
        break;
      case 2:
        printf("Enter quantity min\n");
        scanf_s("%d", &min);
        while (min > 0)
        {
          hor = min / A_PER_B;
          left = min%A_PER_B;//остаток секунд
          printf("%d min is %d hor and %d min\n", min, hor, left);
          printf("Enter next value(Enter 0 for exit!)\n");
          scanf_s("%d", &min);
        }
        break;
      case 3:
        printf("Enter quantity hour\n");
        scanf_s("%d", &hor);
        while (hor > 0)
        {
          min = hor*A_PER_B;
          printf("%d hor is %d min\n", hor, min);
          printf("Enter next value(Enter 0 for exit!)\n");
          scanf_s("%d", &hor);
        }
        break;
      case 4:
        printf("Enter quantity min\n");
        scanf_s("%d", &min);
        while (min > 0)
        {
          sec = min*A_PER_B;
          printf("%d min is %d sec\n", min, sec);
          printf("Enter next value(Enter 0 for exit!)\n");
          scanf_s("%d", &min);
        }
        break;
      case 5:
        printf("Have a nice day!Goodbye!\n");
        return(0);
      }
    }
  printf("Ready!\n");
  return(0);
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question