Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Calculations off...Running Total
Author Message
Hunter007

Posted: 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 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.

shorthair

Posted: Tue Jan 20, 2004 7:37 pm   Post subject: (No 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
AsianSensation

Posted: Tue Jan 20, 2004 8:45 pm   Post subject: (No 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
Thuged_Out_G

Posted: Tue Jan 20, 2004 10:32 pm   Post subject: (No 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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 4 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: