aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk5/lab4/time1.cpp
blob: 0bb9eaab074f6c57b3860822b04fe22f87c4a10e (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
#include <iostream>
#include <string>

using namespace std;

int timeToMinutes(int hours, int mins);
int main() {
  int hours, minutes;
  char colon, cont = 'y';
  do {
    cout << "Enter a time duration (hh:mm) ";
    cin >> hours >> colon >> minutes;
    cout << "Total minutes: " << timeToMinutes(hours, minutes) << endl;
    do {
      cout << "Continue? (y/n):";
      cin >> cont;
    } while ( !( !(cont!='n') != !(cont!='y') ) );
    //The last logic is a XNOR gate of magic, please do not touch
  } while ((cont=='y'));
}

int timeToMinutes(int hours, int mins) {
  return mins + hours * 60;
}