# Assignment

Printable View

• 06-12-2003
cYou
Assignment
I'm having problems with an assignment in C++. The assignment is this:

Make a program that reads two moment of times, given in hours and minutes. Theses moment of times are the start and end for a day of work. After that the hour's pay must be read in. The program are going to estimate the workday in hours and minutes, and estimate the gross wage for a day.
The screen-printout are going to tell how long it has been worked in hours and minutes, and the gross wage.

My code is this:

#include <iostream.h>
main()
{
int Hour1, Hour2, Minute1, Minute2;
double Hour_Pay;

cout << "Key the hour when you start at work: ";
cin >> Hour1;
cout << "Key the minute in that hour you start at work: ";
cin >> Minute1;
cout << "Key the hour when you leave work: ";
cin >> Hour2;
cout << "Key the minute in that hour you leave work: ";
cin >> Minute2;
cout << "Key the hour's pay: ";
cin >> Hour_Pay;

cout << endl;

int Hours = Hour2-Hour1;
int Minutes = Minute1-Minute2;
double Total = (Hours)+(Minutes/60);
double Gross = Total*Hour_Pay;

cout << "You work " << Hours << " hours and " << Minutes << " minutes every day at work."
<< endl
<< "Your gross day's pay is " << Gross << " dollars.";
}

This code is probably not any good at all, i guess i have to do some "variable%variable" but i don't know how or where.

Anyone that does have a suggestion on how to do this assignment?
• 06-12-2003
cYou
What do you mean? Something like this:

#include <iostream.h>
main()
{
double Time1, Time2;
double Hour_Pay;

cout << "Key the time you start at work: ";
cin >> Time1;
cout << "Key the time you leave work: ";
cin >> Time2;
cout << "Key the hour's pay: ";
cin >> Hour_Pay;

cout << endl;

int Hours = Time2-Time1;
int Minutes = Hours%60;
double Total = (Hours)+(Minutes/60);
double Gross = Total*Hour_Pay;

cout << "You work " << Timer << " hours and " << Minutter << " minutes every day at work."
<< endl
<< "Your gross day's pay is " << Brutto << " dollars.";
}

This doesn't work either...

Any suggestions?
• 06-12-2003
cYou
Sorry
Sorry, the "Timer" and "Minutter" at the end should be "Hour" and "Minutes", I've had to translate this from norwegian, i've forgot those two words...

Someone that know what to do with this code?
• 06-12-2003
adrianxw
You're going the wrong way. En time er 60 minutter!

Thus 11:59 is (11*60)+59 and 12:01 is (12*60)+1. As Salem says, you are almost there otherwise.
• 06-12-2003
moonwalker
try this
try this

Code:

```#include <iostream.h> int main() { int hrs1, mns1, hrs2, mns2, hrs, mns; double Hour_Pay, Brutto; cout << "Key the time you start at work: (eg. 15 23): "; cin >> hrs1 >> mns1; cout << "Key the time you leave work: (eg. 18 59): "; cin >> hrs2 >> mns2; cout << "Key the hour's pay: "; cin >> Hour_Pay; cout << endl; mns1 = mns1 + hrs1*60; mns2 = mns2 + hrs2*60; mns = abs(mns2 - mns1); hrs = mns/60; mns = mns % 60; Brutto = Hour_Pay * hrs + ((double)mns)/60 * Hour_Pay; cout << "You work " << hrs << " hours and " << mns << " minutes every day at work." << endl << "Your gross day's pay is " << Brutto << " dollars."; return 0;```

now there's a small thing here..

if someone starts at 23 30 and leaves at 00 30,
it thinks he/she worked for 23 hrs, but in reality, it is
only 1 hr.
I leave it to you to fix it;)

as you can see.. i made a lot of changes in your code..
you didn't even declare certain variables in the beginning..

good luck