loops?

Hey guys,

I am getting back into coding, I have done up a console app that calculates hours/minutes between a start and finish time depending on how many people are 'working' between the start and finish time. I have completed about 90% of it but I am now stuck.

App in summary:
input from user:
1. Start Time
2. Finish Time
3. People working between start and finish time

Code:
Splits the 24 hour start and finish time into two integers for hours and minutes (e.g. Start time 2130, int starthour 21 and int startMin 30 etc)
code calculates hours and minutes divided by people working.

Output:
"Total time from start to finish is x hours and y minutes."
"That's z minutes per person"

The above is all well and good, now this is where I am stuck, my intent is to have the following output, as an example, 3 people working over 2 hours:

Person 1 will work from 1900 until 1940
Person 2 will work from 1940 until 2020
Person 3 will work from 2020 until 2100


I have no idea how to implement this, do I create a loop so that when the minutes integer is >= 60 it resets to 0 and ++hour, how would I do this? then how do I implement a switch case (if I need one?) that uses the above info reference timings and spews it out dependent on how many people are working? E.g. case 1 for one person working, case 2 for 2 people working etc.

I hope I have explained this in a clear manner for you guys, any help would be great.

Kind Regards, Ryan
I think you'll rather need an if.

Aceix.
@Aceix Thanks for the reply

So should I type up an if statement for 1 person, then within that if statement subsequent if statements for adding an hour onto the hour int if minutes >= 60, and then another for hours hitting 24? e.g.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
....
cout << startTimeH << startTimeM << " until ";
startTimeM += minsPerPers;

if (workers == 1) {
  if (startTimeM >= 60) {
    ++startTimeH;
    startTimeM = startTimeM - 60;
    }
    if (startTimeH => 24) {
      startTimeH = startTimeH - 24;
    }
 cout << startTimeH << startTimeM << endl;
 }
cout << startTimeH << startTimeM << " until ";
startTimeM += minsPerPers;
...
// so on for 2 people, 3 people etc? 



Topic archived. No new replies allowed.