Data input & variables - please help

applemac_titanium
applemac_titanium used Ask the Experts™
on
Hi. I'm new to C++ and I would really appreciate if someone could help me out with a program I'm writing.  I want to write a program that needs to calculate working hours at the workplace.

1. It should print out prompt "Enter data: " and the user types in  four numbers: the hours and then minutes for clocking in followed by the hours and minutes for clocking out in the form "12 30 16 45".

2. Both input times should be converted to a total number of minutes since midnight.  E.g. 01:30 would be represented as 90 minutes.

3. Calculate result by subtracting these figures to obtain the required time interval in minutes.  This should be converted to a number of hours and minutes before printing the result in the format: "4h15" and using 24-hour clock times.

Thanks.
giggsy.  
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
To give you a push in the right direction,

1. Use the cout function to print the prompt and use the cin function to read in the numbers.

Example:

cout << "Enter data: ";
cin >> hours1 >> minutes1 >> hours2 >> minutes2;

2. To convert both times to minutes you simply multiply hours1 and hours2 by 60 and add them to minutes1 and minutes2.

Example:

min1 = ( hours1 * 60 ) + minutes1;
min2 = ( hours2 * 60 ) + minutes2;

3. To then get the time interval subtract min1 from min2 and then reduce the result to the correct format.

Example:

interval = min2 - min1;

hours = interval / 60;
minutes = interval - ( hours * 60 );

cout << hours << "h" << minutes;


P.S. All variables used are of type int.

Author

Commented:
Thanks very much Exceter!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial