summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog1/Prakt3/prg1p3_1/main.cpp
blob: 9c84841943ef50ac381a33bc327d2ada4bb21a7c (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Programmieren 1, Praktikum 3, Aufgabe 1
// Sven Eisenhauer
// 12.11.2004
//
// file: main.cpp
//
// purpose: read 2 times (hours, minutes, seconds) from keyboard
//          calculate seconds between this two times
//          uses a function to convert times to seconds
//          
//
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int seconds(int, int, int);

int main()
{
	int hours1,
		minutes1,
		seconds1,
		totalSeconds1,
		hours2,
		minutes2,
		seconds2,
		totalSeconds2;

	// read times from keyboard
	cout << "Please enter 1st hours (0-24): ";
	cin >> hours1;
	cout << "Please enter 1st minutes (0-60): ";
	cin >> minutes1;
	cout << "Please enter 1st seconds (0-60): ";
	cin >> seconds1;

	cout << "Please enter 2nd hours (0-24): ";
	cin >> hours2;
	cout << "Please enter 2nd minutes (0-60): ";
	cin >> minutes2;
	cout << "Please enter 2nd seconds (0-60): ";
	cin >> seconds2;

	// convert to seconds
	totalSeconds1=seconds(hours1,minutes1,seconds1);
	totalSeconds2=seconds(hours2,minutes2,seconds2);

    cout << endl << "Difference in seconds is: ";
	// which is the bigger value and substract the lower one
	if (totalSeconds1 > totalSeconds2)
		cout << totalSeconds1 - totalSeconds2;
	else
		cout << totalSeconds2 - totalSeconds1;

	cout << endl;

	return 0;
}// end main

// function seconds
int seconds (int h, int min, int sec)
{
	return h*3600+min*60+sec;
} // end function seconds