Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4097188
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:08:30+00:00 2026-05-20T20:08:30+00:00

I’m working on a programming problem. Note: This is not a student project. I

  • 0

I’m working on a programming problem.

Note: This is not a student project. I am working on this for a new Quest for the website Try My Quest Dot Com, for which i am the admin.

Problem:

Jenny just started work as a programmer for Justine’s Java Workshop. She is paid $10
an hour, with a few exceptions. She earns an extra $1.50 an hour for any part of a day where she works more than 8 hours, and an extra $2.50 an hour for hours beyond 40 in any one week. Also, she earns a 125% bonus for working on Saturday, and a 50% bonus for working on Sunday. The bonuses for Saturday and Sunday are computed based on the hours worked those days; they are not used to calculate any bonus for working more than 40 hours in a week. You’ll be given the number of hours Jenny worked each day in a week (Sunday, Monday, etc ), and you need to compute her salary for the week. The input will be positive integers, less than or equal to 24. The output must be formatted with a dollar sign and rounded up to the nearest penny. For example, $2″ and $2.136666″ are wrong answers; the correct versions are $2.00″ and $2.14″, respectively.

Anyway, i am trying to write this in Delphi (No form project). I pass the program a command line argument – timecard.dat

input

0, 8, 8, 8, 8, 8, 0
0, 10, 10, 10, 10, 10, 0
0, 0, 8, 8, 8, 8, 8
0, 0, 0, 10, 10, 10, 10
10, 10, 10, 9, 9, 9, 9

Output

Output #1: $400.00
Output #2: $540.00
Output #3: $500.00
Output #4: $540.75
Output #5: $905.88

My Out put however is:

Output #1: $400.00
Output #2: $540.00
Output #3: $500.00

Output #4: $537.00
Output #5: $902.50

The last two output values of mine are different from the actual results. Not sure why, and the more i stare at the code, the less i see it

Can anyone tell me what i have done wrong?

program ACSL_Time_Cards;
{assumes Sunday = 1, Monday 3, etc}
uses
  SysUtils,
  Dialogs;

const
 HourlyWage = 10.00;
 OverEightWage = 1.50;
 OverFortyWage = 2.50;
var
 F: TextFile;
 I, ArrayIndex: Integer;
 WeeklyHours: Array[0..6] of Integer; //weekly hours
 HourStr, LineStr: String;
 TotalHours, TotalOverFortyHours, TotalOverEightHours, TotalSatHours, TotalSunHours: Integer;
 TotalWages: Real;
begin
 //initialize variables
 TotalHours:= 0;
 TotalOverEightHours:= 0;
 TotalOverFortyHours:= 0;
 TotalSatHours:= 0;
 TotalSunHours:= 0;
 TotalWages:= 0.00;
 ArrayIndex:= 0;
 //open file "timecard.dat" for input
 if FileExists(ParamStr(1)) then
 begin
  AssignFile(F, ParamStr(1));
  Reset(F);
  //step through file and extract each line and store in hoursStr
  while not EOF(F) do
  begin
   Readln(F, LineStr);
   //step through hours string and fill Array with weekly hours
   for I:= 1 to length(LineStr) do
   begin
    //if character is not a ',' then add it to hourStr
    if LineStr[I] <> ',' then
     HourStr:= HourStr + LineStr[I]
    else
    begin
     //add HourStr to Array
     WeeklyHours[ArrayIndex]:= StrToInt(HourStr);
     //reset the variable
     HourStr:= '';
     //increment Variable
     Inc(ArrayIndex);
    end; //else
   end; //for I:= 1 to length(HoursStr) do
   //clean up by adding the last remaining one
   WeeklyHours[ArrayIndex]:= StrToInt(HourStr);
   //step through array and figure out overtime Daily and Weekly
   for I:= Low(WeeklyHours) to High(WeeklyHours) do
   begin
    TotalHours:= TotalHours + WeeklyHours[I];
    if WeeklyHours[I] > 8 then
     TotalOverEightHours:= TotalOverEightHours + WeeklyHours[I]-8;
     //get sunday hours
     if I + 1 = 1 then
      TotalSunHours:= TotalSunHours + WeeklyHours[I];
     //get saturday hours
     if I + 1 = 7 then
     TotalSatHours:= TotalSatHours + WeeklyHours[I];
   end;
   //get total over 40 hours
   if TotalHours > 40 then
    TotalOverFortyHours:= TotalHours-40;
  //compute Regular Hours
  TotalWages:= TotalWages + TotalHours * 10.00;
  //compute overtime hours

  TotalWages:= TotalWages + TotalOverEightHours * 1.50;
  TotalWages:= TotalWages + TotalOverFortyHours * 2.50;
  //compute bonuses
  TotalWages:= TotalWages + (TotalSatHours * 10.00) * 1.25;
  TotalWages:= TotalWages + (TotalSunHours * 10.00) * 0.50;

  ShowMessage('TotalWages: ' + FormatFloat('$0.00', TotalWages));
  //reset variables
  TotalWages:= 0.00;
  TotalHours:= 0;
  TotalOverEightHours:= 0;
  TotalOverFortyHours:= 0;
  TotalSatHours:= 0;
  TotalSunHours:= 0;
  HourStr:= '';
  ArrayIndex:= 0;
  end; //while not EOF(F) do
  CloseFile(F);
 end
 else
 ShowMessage('File does not exist!');
end.

I’m sure there are many ways that this could have been written better. I really am just interested in why my values different from the expected values. Thanks!

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:08:31+00:00Added an answer on May 20, 2026 at 8:08 pm

    For a simple problem like this, you might want to write it out by hand and then see if your code follows the same steps you did.

    For Output 4, the 125% bonus for Saturday is not including the $1.50 per hour extra after 8:

    she should earn

    Wed: $103    | $100 for 10 hours plus $3 for 2 hours over 8
    Thu: $103    | $100 for 10 hours plus $3 for 2 hours over 8
    Fri: $103    | $100 for 10 hours plus $3 for 2 hours over 8
    Sat: $231.75 | ($100 for 10 hours, $3 for 2 hours over 8), $128.75 for 125% bonus
    

    for a total of 540.75

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.