Specify Time (C++)

Associate
Joined
28 Jul 2014
Posts
694
Location
Liverpool
I am trying to write a simple console application that will accept a string from the keyboard (representing a time period in the format HH:MM). This string must them be decomposed into two integers for hours and mins before being resolved into total mins (i.e. 02:20 would resolve to 140 mins etc). The resulting calculation should then be printed to the screen.

This is my code so far
Code:
#include <iostream> //include iostream to get access to cin and cout
#include <string> //include string to get access to a string variable.

using namespace std;

class time {
	int Hr, Min;
public:
	void set_values(int);
	void Show(void);
};

int main()
{
	std::string time;
	int hours = 60;
	int min = 60;

	void set_values(int) {
		Hr = Secs / 3600;
		Min = (Secs % 3600) / 60;
	}

	cout << "Specify time (HH:MM) : ";
	cin >> min;

//Specify system pause
system("PAUSE");
return 0;

}

Output I am trying to print
Code:
Specify Time (HH:MM) : 02:20
02:20 = 140 Mins !

Any help would be appreciated, thanks in advance.
 
Associate
OP
Joined
28 Jul 2014
Posts
694
Location
Liverpool

Thanks a lot for the quick reply. It is similar to what I am trying to achieve, and I am getting this output:

Code:
Speicify Time (HH:MM) : 02:20
Hours : 2
Mins : 20

but how would I have it so that the (HH:MM) would convert to minutes like so:

Code:
Specify Time (HH:MM) : 02:20
02:20 = 140 Mins !
 
Back
Top Bottom