Someone help me ! :(

i didn't know how to calculate the total hours and minutes of work...

can some one give me advice?


#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <time.h>

int main ()

{

int hrs_in,min_in;
int hrs_out,min_out;

char days [6][11] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
char colon;
char Name[40];
char MI[40];
char LastName[50];

clrscr ();

cout<<"Enter Employee Name";
cout<<"\n\nFirst Name: ";
cin.getline(Name,40);
cout<<"\nMiddle Initial: ";
cin.getline(MI,40);
cout<<"\nLast Name: ";
cin.getline(LastName,50);

clrscr ();

cout<<"Employee Name";
cout<<"\n\nFull Name: "<<Name<<" "<<MI<<". "<<LastName;

cout<<"\n\n\nEnter Log-in for "<<days[0]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[0]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[1]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[1]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[2]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[2]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[3]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[3]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[4]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[4]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[5]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[5]<<": ";
cin>>hrs_out>>colon>>min_out;




getche ();
return 0;
}
Hint: The total number of minutes elapsed from midnight 00:00 till HH:MM is HH * 60 + MM
where can i put the codes?

sorry im just a beginner :(
Last edited on
Hint 2: The The total number of minutes elapsed from
hrs_in:min_in to a later time point on the same day hrs_out:min_out is:
( hrs_out * 60 + min_out ) - ( hrs_in * 60 + min_in )
can you check this ?
can say which part im wrong? :(

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>

int main ()

{


int hrs_in,hrs_out,min_in,min_out;

char days [6][11] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
char colon;
char Name[40];
char MI[40];
char LastName[50];

clrscr ();

cout<<"Enter Employee Name";
cout<<"\n\nFirst Name: ";
cin.getline(Name,40);
cout<<"\nMiddle Initial: ";
cin.getline(MI,40);
cout<<"\nLast Name: ";
cin.getline(LastName,50);

clrscr ();

cout<<"Employee Name";
cout<<"\n\nFull Name: "<<Name<<" "<<MI<<". "<<LastName;

cout<<"\n\n\nEnter Log-in for "<<days[0]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[0]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[1]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[1]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[2]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[2]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[3]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[3]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[4]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[4]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[5]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[5]<<": ";
cin>>hrs_out>>colon>>min_out;


int totalwork;

totalwork=(hrs_out*.60+min_out)-(hrs_in*.60+min_in);

cout<<"\nTotal Worked Hours: ";cout<<totalwork;


getche ();
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cout<<"\nEnter Log-in for "<<days[5]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[5]<<": ";
cin>>hrs_out>>colon>>min_out;

// at this point, hrs_in:min_in and hrs_out:min_out
// contain the in and out times for Friday 

int totalwork;

totalwork=(hrs_out*.60+min_out)-(hrs_in*.60+min_in); // * 0.60 ???

// (hrs_out*60+min_out)-(hrs_in*60+min_in) would give
// the total number of *minutes* of work on that one day. 
Last edited on
oh thank you!!

you help me alot!! :D
and now im just wondering how to convert minutes to hours :D
That's easy, int hours = minutes / 60;
@ishin03

Firstly, please always use code tags - select your code, then press the <> button on the right. It is much easier because it formats the code correctly, and we can quote line numbers.

You should use the double type for your variables if you are going to have multiplication / division by fractions. With division, always check for divide by 0.

With this part (better with line numbers here):

1
2
3
4
5
6
7
8
cout<<"\n\n\nEnter Log-in for "<<days[0]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[0]<<": ";
cin>>hrs_out>>colon>>min_out;
cout<<"\nEnter Log-in for "<<days[1]<<": ";
cin>>hrs_in>>colon>>min_in;
cout<<"Enter Log-out for "<<days[1]<<": ";
cin>>hrs_out>>colon>>min_out;


Consider using a for loop, instead of the repeated code.

HTH
@ishin03, @Antares64

int hours, mins;

To make sure you always convert to an integer number of hours, try the following:

1
2
3
int temp;
temp = mins % 60; //gives us the remainder when (mins / 60)
hours = (mins - temp) / 60; //hours will be an integer, and temp the remaining minutes 
shinkansen is right, try doing what he posted
Topic archived. No new replies allowed.