Assignment

This is a discussion on Assignment within the C++ Programming forums, part of the General Programming Boards category; I'm having problems with an assignment in C++. The assignment is this: Make a program that reads two moment of ...

  1. #1
    cYou
    Guest

    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?

  2. #2
    cYou
    Guest
    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?

  3. #3
    cYou
    Guest

    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?

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    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.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    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
    Last edited by moonwalker; 06-12-2003 at 09:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 03:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 07:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 02:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21