Computer Science Canada

Calculations off...Running Total

Author:  Hunter007 [ Tue Jan 20, 2004 7:33 pm ]
Post subject:  Calculations off...Running Total

OK I know that I need to have a running total to keep track of the numbers and I posted a question similiar to this before. However when I tryed to impliment it, it didn't work Confused I did what I thought was supposed to be done, but the calculations aren't working.

code:

var name : string
var numemployee : int := 0
var hourlywage : real
var hours : real
var overtime : real := 0
var regpay : real
var overpay : real
var totpay : real
var totreghours : real := 0
var totregpay : real := 0
var totovertime : real := 0
var totoverpay : real := 0
var totalhours : real := 0
var grandtot : real := 0

put "How many employees? " ..
get numemployee

cls

for i : 1 .. numemployee
    put "What is the employee's name? " ..
    get name : *

    put "What is ", name, "'s hourly wage? $" ..
    get hourlywage

    put "How many hours did ", name, " work? " ..
    get hours

    if hours > 40 then
        overtime := hours - 40
        hours := hours - overtime
    end if

    regpay := hourlywage * hours
    overpay := (overtime * hourlywage) + (overtime * (hourlywage / 2))
    totpay := regpay + overpay
    totreghours := totreghours + hours
    totregpay := totregpay + regpay
    totovertime := totovertime + overtime
    totoverpay := totoverpay + overpay
    totalhours := totalhours + totreghours + totovertime
    grandtot := grandtot + totoverpay + totregpay
    put ""
    put name, " worked ", overtime, " overtime hours and earned $", totpay : 2 : 2

    delay (2500)
    cls

    regpay := 0
    overpay := 0
    totpay := 0

end for

put "SUMMARY:"
put "Number of Employees: ", numemployee
put ""
put "Regular hours worked: ", totreghours
put "Regular earnings paid: $", totregpay : 2 : 2
put ""
put "Overtime hours worked: ", totovertime
put "Overtime earnings paid: $", totoverpay : 2 : 2
put ""
put "Total hours worked: ", totalhours
put "Total earnings paid: $", grandtot : 2 : 2


Any help would be greatly appreciated. Very Happy

Author:  shorthair [ Tue Jan 20, 2004 7:37 pm ]
Post subject: 

When i did my payroll system i made a record of the main waraiables like the name and employee number and sin # you have to store these values in a " Binary file" that can be read written , modded , seeked and told , thats how you do this program propery ,save the values for later use
this method is very easy once you learn how ot make a record ,


Your calculations are wrong becuase you are breaking the 3 rule of programming SEQUENCE , if you trace your program you will see that your variables are changing and when they do , your calculations go off
you need to make sure you do your calculations in the correct order

Author:  AsianSensation [ Tue Jan 20, 2004 8:45 pm ]
Post subject: 

shorthair wrote:
you need to make a record of the main waraiables like the name ans stuff


not really, structures are just ways of organizing a person's code. It's perfectly fine to not use structures and still be able to do a good program. I know forgot to use structures for my FP last year. It basicly depends on how well you can keep track of stuff yourself. If you are really good, then you can just declare every single variable as one big array. But then again, that requires a great amount of mental discipline

Author:  Thuged_Out_G [ Tue Jan 20, 2004 10:32 pm ]
Post subject: 

using a record for this would make things much easier to organize

code:

type employeeData
record
var pay:real
var hours:real
var name:string
end record
var emp:int

put "How many employess: "..
get emp

var data:array 1..emp of employeeData


you store data in it like such

code:

var hours1:int
var pay1:real
var name1:string

for i:1..emp
put "Enter employee name: "
get name1
put "Enter pay rate: "
get pay1
put "Enter hours worked"
get hours1
data(i).name:=name1
data(i).hours:=hours1
data(i).pay:=pay1
end for


: