Advertisement
desislava_topuzakova

05. Time + 15 Minutes

Jan 17th, 2021
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     //1. часове и минути (вход)
  7.     int currentHour, currentMinute;
  8.     cin >> currentHour >> currentMinute;
  9.  
  10.     // 2. часове и минути -> минути
  11.     int totalTimeMinutes = currentHour * 60 + currentMinute;
  12.  
  13.     //3. минути + 15 мин
  14.     int timeAfter15 = totalTimeMinutes + 15;
  15.  
  16.     //4. преобразуваме в часове и минути
  17.         //часове = минути / 60
  18.         int hourAfter = timeAfter15 / 60;
  19.         int minuteAfter = timeAfter15 % 60;
  20.  
  21.         //ако час == 24 -> час = 0
  22.         if (hourAfter == 24) {
  23.             hourAfter = 0; //hourAfter = hourAfter - 24;
  24.         }
  25.  
  26.      //5. печатаме
  27.         if (minuteAfter <= 9) {
  28.             //час:0минути
  29.             cout << hourAfter << ":0" << minuteAfter << endl;
  30.         } else {
  31.             //час:минути
  32.             cout << hourAfter << ":" << minuteAfter << endl;
  33.         }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement