aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk5/lab4/time2.cpp
blob: 0126e23d1718c2302e7c690ec5a7d1f0ab105bd5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <string>

using namespace std;

void minutesToTime(int minute_value, int& hours, int& mins);
int main() {
  int hours, mins;
  char cont = 'y';
  do {
    cout << "Enter a number of minutes: ";
    cin >> mins;
    minutesToTime(mins, hours, mins);
    cout << hours << ":";
    if (mins<10) {
      cout << '0' << mins << endl;
    } else {
      cout << mins << endl;
    }
    do {
      cout << "Continue? (y/n):";
      cin >> cont;
    } while ( !( !(cont!='n') != !(cont!='y') ) );
    //The last logic is a XNOR gate of magic, touching will disturb the magic
  } while ((cont=='y'));
}

void minutesToTime(int minute_value, int& hours, int& mins) {
  mins=minute_value%60;
  hours=0;
  for (int i=minute_value/60; i>0; i--) {
    hours++;
    if (hours>12)
      hours=1;
  }
}