Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How can I place this in a function? Posted by Rodimus Prime on 23 Mar 2004 at 4:54 PM
Hello,

I have got my program running to calculate grosspay and taxes, but I am trying to calculate the grosspay using a function.
I have become kind of stuck with this.
Can somebody plz give me some help?

uses
   crt;

const
   normalhours = 40;
   taxrate1 = 0.195;
   taxrate2 = 0.33;
   taxrate3 = 0.39;

var
   empname : string[20];
   payrate , errorcode : real;
   workedhours , errorcode2 : real;
   grosspay : real;
   taxdeduction1 , taxdeduction2, taxdeduction3 : real;

begin
   clrscr;
   repeat
      write('Enter the hourly pay rate: ');
      {$I-}
      readln(payrate);
      {$I+}
      errorcode := IOResult;
         if errorcode <> 0 then
            begin
               sound(1000);
               delay(100);
               nosound;
            end;
   until errorcode = 0;

   repeat
      write('Enter the hours worked this week: ');
      {$I-}
      readln(workedhours);
      {$I+}
      errorcode := IOResult;
         if errorcode <> 0 then
            begin
               sound(1000);
               delay(100);
               nosound;
            end;
   until errorcode = 0;
   writeln;


  function calgrosspay( workedhours, payrate: real) real;
   var
      paidhours, premiumhours : real;
   begin
      overtimehours := workedhours - normalhours;
         if overtimehours <= 0
         begin
            paidhours := workedhours;
         end
         else if overtimehours > 0 then
         begin
            premiumhours := overtimehours * payrate * 1.5;
         end;

         paidhours := normalhours * payrate;
         grosspay := premiumhours + paidhours;

   end;


   if grosspay <= 728.77 then
      taxdeduction1 := grosspay * taxrate1
   else
   begin
      taxdeduction1 := 728.77 * taxrate1;
      if grosspay <= 1150.68 then
         taxdeduction2 := taxdeduction1 + (grosspay - 728.77) * taxrate2
      else
      begin
      taxdeduction2 :=  taxdeduction1 + (1150.68 - 728.77) * taxrate2;
      taxdeduction3 := taxdeduction2 + (grosspay - 1150.68) * taxrate3;
      end;
   end;

   writeln('Current employee is: ', empname);
   writeln('Employee hourly pay rate is: $', payrate:2:2);
   writeln('The hours the employee worked this week is: ', workedhours:2:2);
   writeln('Employee grosspay for this week is: $', grosspay(workedhours, payrate:2:2);
   writeln;
   writeln;
   writeln('The 19.5% tax rate results in a S', taxdeduction1:2:2 ,' tax deduction');
   writeln('from the first $728.77 of the employees grosspay.');
   writeln;
   writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction');
   writeln('of anything above $728.77 and below $1150.68 results in $', taxdeduction2:2:2);
   writeln('being deducted from the employees grosspay.');
   writeln;
   writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction');
   writeln('of anything above $728.77 and below $1150.68, plus a further 39% tax ');
   writeln('deduction of any amount above $1150.68 results in a total tax deduction ');
   writeln('of $', taxdeduction3:2:2);
   writeln;
   writeln('Press ENTER to exit the program');
   readln;
end.


Report
Re: How can I place this in a function? Posted by zibadian on 23 Mar 2004 at 8:20 PM
: Hello,
:
: I have got my program running to calculate grosspay and taxes, but I am trying to calculate the grosspay using a function.
: I have become kind of stuck with this.
: Can somebody plz give me some help?
:
:
: uses
:    crt;
: 
: const
:    normalhours = 40;
:    taxrate1 = 0.195;
:    taxrate2 = 0.33;
:    taxrate3 = 0.39;
: 
: var
:    empname : string[20];
:    payrate , errorcode : real;
:    workedhours , errorcode2 : real;
:    grosspay : real;
:    taxdeduction1 , taxdeduction2, taxdeduction3 : real;
: 
: begin
:    clrscr;
:    repeat
:       write('Enter the hourly pay rate: ');
:       {$I-}
:       readln(payrate);
:       {$I+}
:       errorcode := IOResult;
:          if errorcode <> 0 then
:             begin
:                sound(1000);
:                delay(100);
:                nosound;
:             end;
:    until errorcode = 0;
: 
:    repeat
:       write('Enter the hours worked this week: ');
:       {$I-}
:       readln(workedhours);
:       {$I+}
:       errorcode := IOResult;
:          if errorcode <> 0 then
:             begin
:                sound(1000);
:                delay(100);
:                nosound;
:             end;
:    until errorcode = 0;
:    writeln;
: 
: 
:   function calgrosspay( workedhours, payrate: real) real;
:    var
:       paidhours, premiumhours : real;
:    begin
:       overtimehours := workedhours - normalhours;
:          if overtimehours <= 0
:          begin
:             paidhours := workedhours;
:          end
:          else if overtimehours > 0 then
:          begin
:             premiumhours := overtimehours * payrate * 1.5;
:          end;
: 
:          paidhours := normalhours * payrate;
:          grosspay := premiumhours + paidhours;
: 
:    end;
: 
: 
:    if grosspay <= 728.77 then
:       taxdeduction1 := grosspay * taxrate1
:    else
:    begin
:       taxdeduction1 := 728.77 * taxrate1;
:       if grosspay <= 1150.68 then
:          taxdeduction2 := taxdeduction1 + (grosspay - 728.77) * taxrate2
:       else
:       begin
:       taxdeduction2 :=  taxdeduction1 + (1150.68 - 728.77) * taxrate2;
:       taxdeduction3 := taxdeduction2 + (grosspay - 1150.68) * taxrate3;
:       end;
:    end;
: 
:    writeln('Current employee is: ', empname);
:    writeln('Employee hourly pay rate is: $', payrate:2:2);
:    writeln('The hours the employee worked this week is: ', workedhours:2:2);
:    writeln('Employee grosspay for this week is: $', grosspay(workedhours, payrate:2:2);
:    writeln;
:    writeln;
:    writeln('The 19.5% tax rate results in a S', taxdeduction1:2:2 ,' tax deduction');
:    writeln('from the first $728.77 of the employees grosspay.');
:    writeln;
:    writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction');
:    writeln('of anything above $728.77 and below $1150.68 results in $', taxdeduction2:2:2);
:    writeln('being deducted from the employees grosspay.');
:    writeln;
:    writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction');
:    writeln('of anything above $728.77 and below $1150.68, plus a further 39% tax ');
:    writeln('deduction of any amount above $1150.68 results in a total tax deduction ');
:    writeln('of $', taxdeduction3:2:2);
:    writeln;
:    writeln('Press ENTER to exit the program');
:    readln;
: end.
: 

:
:
All functions and procedures are defined before the begin of the main program block. So your code should look like:
uses
  Crt;

function CalGrossPay(workedhours, payrate: real) real;
begin
  { code of the function }
end;

var
  empname: string[20];
  { other variables }

begin
  { main program block }
end.

I've abbreviated the code to shorten the message.
Report
Re: How can I place this in a function? Posted by bondan83 on 24 Mar 2004 at 3:11 AM
You must place the FUNCTION section out of the main BEGIN..END section.
So the code should be write like:

---------------------------------------------------
uses
crt;

const
normalhours = 40;
taxrate1 = 0.195;
taxrate2 = 0.33;
taxrate3 = 0.39;

var
empname : string[20];
payrate , errorcode : real;
overtimehours, workedhours , errorcode2 : real;
grosspay : real;
taxdeduction1 , taxdeduction2, taxdeduction3 : real;

function calgrosspay( workedhours, payrate: real): real;
var
paidhours, premiumhours : real;
begin
overtimehours := workedhours - normalhours;
if overtimehours <= 0 then
begin
paidhours := workedhours;
end
else if overtimehours > 0 then
begin
premiumhours := overtimehours * payrate * 1.5;
end;

paidhours := normalhours * payrate;
grosspay := premiumhours + paidhours;

end;


begin
clrscr;
repeat
write('Enter the hourly pay rate: ');
{$I-}
readln(payrate);
{$I+}
errorcode := IOResult;
if errorcode <> 0 then
begin
sound(1000);
delay(100);
nosound;
end;
until errorcode = 0;

repeat
write('Enter the hours worked this week: ');
{$I-}
readln(workedhours);
{$I+}
errorcode := IOResult;
if errorcode <> 0 then
begin
sound(1000);
delay(100);
nosound;
end;
until errorcode = 0;
writeln;




if grosspay <= 728.77 then
taxdeduction1 := grosspay * taxrate1
else
begin
taxdeduction1 := 728.77 * taxrate1;
if grosspay <= 1150.68 then
taxdeduction2 := taxdeduction1 + (grosspay - 728.77) * taxrate2
else
begin
taxdeduction2 := taxdeduction1 + (1150.68 - 728.77) * taxrate2;
taxdeduction3 := taxdeduction2 + (grosspay - 1150.68) * taxrate3;
end;
end;

writeln('Current employee is: ', empname);
writeln('Employee hourly pay rate is: $', payrate:2:2);
writeln('The hours the employee worked this week is: ', workedhours:2:2);
writeln('Employee grosspay for this week is: $', calgrosspay(workedhours, payrate));
writeln;
writeln;
writeln('The 19.5% tax rate results in a S', taxdeduction1:2:2 ,' tax deduction');
writeln('from the first $728.77 of the employees grosspay.');
writeln;
writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction');
writeln('of anything above $728.77 and below $1150.68 results in $', taxdeduction2:2:2);
writeln('being deducted from the employees grosspay.');
writeln;
writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction');
writeln('of anything above $728.77 and below $1150.68, plus a further 39% tax ');
writeln('deduction of any amount above $1150.68 results in a total tax deduction ');
writeln('of $', taxdeduction3:2:2);
writeln;
writeln('Press ENTER to exit the program');
readln;
end.
---------------------------------------------------------------ENDCODE
Report
Re: How can I place this in a function? Posted by Rodimus Prime on 24 Mar 2004 at 4:50 AM
Hi, thanks for your help. But when I tried to compile this code, it tells me a ";" is expected and the cursor is placed at the beginning of else. I don't think I should put a ; at the end of the first end, right?
so why doesn't it run?

thank you

: You must place the FUNCTION section out of the main BEGIN..END section.
: So the code should be write like:
:
: ---------------------------------------------------
: uses
: crt;
:
: const
: normalhours = 40;
: taxrate1 = 0.195;
: taxrate2 = 0.33;
: taxrate3 = 0.39;
:
: var
: empname : string[20];
: payrate , errorcode : real;
: overtimehours, workedhours , errorcode2 : real;
: grosspay : real;
: taxdeduction1 , taxdeduction2, taxdeduction3 : real;
:
: function calgrosspay( workedhours, payrate: real): real;
: var
: paidhours, premiumhours : real;
: begin
: overtimehours := workedhours - normalhours;
: if overtimehours <= 0 then
: begin
: paidhours := workedhours;
: end
: else if overtimehours > 0 then
: begin
: premiumhours := overtimehours * payrate * 1.5;
: end;
:
: paidhours := normalhours * payrate;
: grosspay := premiumhours + paidhours;
:
: end;
:
:
: begin
: clrscr;
: repeat
: write('Enter the hourly pay rate: ');
: {$I-}
: readln(payrate);
: {$I+}
: errorcode := IOResult;
: if errorcode <> 0 then
: begin
: sound(1000);
: delay(100);
: nosound;
: end;
: until errorcode = 0;
:
: repeat
: write('Enter the hours worked this week: ');
: {$I-}
: readln(workedhours);
: {$I+}
: errorcode := IOResult;
: if errorcode <> 0 then
: begin
: sound(1000);
: delay(100);
: nosound;
: end;
: until errorcode = 0;
: writeln;
:
:
:
:
: if grosspay <= 728.77 then
: taxdeduction1 := grosspay * taxrate1
: else
: begin
: taxdeduction1 := 728.77 * taxrate1;
: if grosspay <= 1150.68 then
: taxdeduction2 := taxdeduction1 + (grosspay - 728.77) * taxrate2
: else
: begin
: taxdeduction2 := taxdeduction1 + (1150.68 - 728.77) * taxrate2;
: taxdeduction3 := taxdeduction2 + (grosspay - 1150.68) * taxrate3;
: end;
: end;
:
: writeln('Current employee is: ', empname);
: writeln('Employee hourly pay rate is: $', payrate:2:2);
: writeln('The hours the employee worked this week is: ', workedhours:2:2);
: writeln('Employee grosspay for this week is: $', calgrosspay(workedhours, payrate));
: writeln;
: writeln;
: writeln('The 19.5% tax rate results in a S', taxdeduction1:2:2 ,' tax deduction');
: writeln('from the first $728.77 of the employees grosspay.');
: writeln;
: writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction');
: writeln('of anything above $728.77 and below $1150.68 results in $', taxdeduction2:2:2);
: writeln('being deducted from the employees grosspay.');
: writeln;
: writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction');
: writeln('of anything above $728.77 and below $1150.68, plus a further 39% tax ');
: writeln('deduction of any amount above $1150.68 results in a total tax deduction ');
: writeln('of $', taxdeduction3:2:2);
: writeln;
: writeln('Press ENTER to exit the program');
: readln;
: end.
: ---------------------------------------------------------------ENDCODE
:

Report
Re: How can I place this in a function? Posted by zibadian on 24 Mar 2004 at 12:00 PM
: Hi, thanks for your help. But when I tried to compile this code, it tells me a ";" is expected and the cursor is placed at the beginning of else. I don't think I should put a ; at the end of the first end, right?
: so why doesn't it run?
:
: thank you
:
: : You must place the FUNCTION section out of the main BEGIN..END section.
: : So the code should be write like:
: :
: : ---------------------------------------------------
: : uses
: :    crt;
: : 
: : const
: :    normalhours = 40;
: :    taxrate1 = 0.195;
: :    taxrate2 = 0.33;
: :    taxrate3 = 0.39;
: : 
: : var
: :    empname : string[20];
: :    payrate , errorcode : real;
: :    overtimehours, workedhours , errorcode2 : real;
: :    grosspay : real;
: :    taxdeduction1 , taxdeduction2, taxdeduction3 : real;
: : 
: : function calgrosspay( workedhours, payrate: real):  real;
: :    var
: :       paidhours, premiumhours : real;
: :    begin
: :       overtimehours := workedhours - normalhours;
: :          if overtimehours <= 0 then
: :          begin
: :             paidhours := workedhours;
: :          end
: :          else if overtimehours > 0 then
: :          begin
: :             premiumhours := overtimehours * payrate * 1.5;
: :          end;
: : 
: :          paidhours := normalhours * payrate;
: :          grosspay := premiumhours + paidhours;
: : 
: :    end;
: : 
: : 
: : begin
: :    clrscr;
: :    repeat
: :       write('Enter the hourly pay rate: ');
: :       {$I-}
: :       readln(payrate);
: :       {$I+}
: :       errorcode := IOResult;
: :          if errorcode <> 0 then
: :             begin
: :                sound(1000);
: :                delay(100);
: :                nosound;
: :             end;
: :    until errorcode = 0;
: : 
: :    repeat
: :       write('Enter the hours worked this week: ');
: :       {$I-}
: :       readln(workedhours);
: :       {$I+}
: :       errorcode := IOResult;
: :          if errorcode <> 0 then
: :             begin
: :                sound(1000);
: :                delay(100);
: :                nosound;
: :             end;
: :    until errorcode = 0;
: :    writeln;
: : 
: : 
: : 
: : 
: :    if grosspay <= 728.77 then
: :       taxdeduction1 := grosspay * taxrate1
: :    else
: :    begin
: :       taxdeduction1 := 728.77 * taxrate1;
: :       if grosspay <= 1150.68 then
: :          taxdeduction2 := taxdeduction1 + (grosspay - 728.77) * taxrate2
: :       else
: :       begin
: :       taxdeduction2 :=  taxdeduction1 + (1150.68 - 728.77) * taxrate2;
: :       taxdeduction3 := taxdeduction2 + (grosspay - 1150.68) * taxrate3;
: :       end;
: :    end;
: : 
: :    writeln('Current employee is: ', empname);
: :    writeln('Employee hourly pay rate is: $', payrate:2:2);
: :    writeln('The hours the employee worked this week is: ', workedhours:2:2);
: :    writeln('Employee grosspay for this week is: $', calgrosspay(workedhours, payrate));
: :    writeln;
: :    writeln;
: :    writeln('The 19.5% tax rate results in a S', taxdeduction1:2:2 ,' tax deduction');
: :    writeln('from the first $728.77 of the employees grosspay.');
: :    writeln;
: :    writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction');
: :    writeln('of anything above $728.77 and below $1150.68 results in $', taxdeduction2:2:2);
: :    writeln('being deducted from the employees grosspay.');
: :    writeln;
: :    writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction');
: :    writeln('of anything above $728.77 and below $1150.68, plus a further 39% tax ');
: :    writeln('deduction of any amount above $1150.68 results in a total tax deduction ');
: :    writeln('of $', taxdeduction3:2:2);
: :    writeln;
: :    writeln('Press ENTER to exit the program');
: :    readln;
: : end.
: : ---------------------------------------------------------------

: :
:
:
I just compiled this code successfully. Could you tell us which else, since you have 3?
Report
Re: How can I place this in a function? Posted by Rodimus Prime on 24 Mar 2004 at 10:28 PM
This message was edited by Rodimus Prime at 2004-3-25 2:4:49

Hi,
Thank you too for wanting to help me out. Ok, it was the first Else where I got the error message. But I tested the program on two different computers, and it compiled. So there's probably something wrong with the Turbo version on that computer that couldn't compile it.
But what the problem is now, is that, the function isn't called I think! I enter some input, but the grosspay always shows up as $0.00!!
I have looked at some examples of other functions in PASCAL, and I can't get my head round why the function isn't used, coz I have checked my algorithm, and if I enter a $31.5 payrate, and 43 hours worked for example. The grosspay should come out as $1401.75, but it's just $0.00

Thank you

EDIT: It does display something in grosspay when I don't round it, but it give this long real number which isn't of much use. But when I added :2:2) to the end of the function, that's when grosspay displayed $0.00

Report
Re: How can I place this in a function? Posted by Rodimus Prime on 25 Mar 2004 at 9:15 PM
Hi,

I got the program compiling succesfully now too. I don't what the problem was. Perhaps one of the compilers on the computer.
I have also decided to put the tax calculations into a function.
My question is, how can I make the output print every tax deduction amount after each deduction?
Currently it displays the first tax deduction for all three. It's probably obvious that it shouldn't be there.
But where do the other 2 taxdeduction results go?

Further help is appreciated


uses
   crt;

const
   normalhours = 40;
   taxrate1 = 0.195;
   taxrate2 = 0.33;
   taxrate3 = 0.39;

var
   empname : string[20];
   payrate , errorcode : real;
   workedhours , overtimehours , errorcode2 : real;
   grosspay : real;
   taxdeduction1 , taxdeduction2, taxdeduction3 : real;


function calgrosspay(workedhours, payrate: real): real;
   var
      paidhours, premiumhours : real;

   begin
      overtimehours := workedhours - normalhours;
         if overtimehours <= 0 then
         begin
            paidhours := workedhours;
         end
         else if overtimehours > 0 then
         begin
            premiumhours := overtimehours * payrate * 1.5;
         end;

         paidhours := normalhours * payrate;
         grosspay := premiumhours + paidhours;
         calgrosspay := grosspay;
   end;

   function caltaxdeduction(grosspay: real): real;
   begin
      if grosspay <= 728.77 then
         taxdeduction1 := grosspay * taxrate1
      else
      begin
         taxdeduction1 := 728.77 * taxrate1;
      if grosspay <= 1150.68 then
         taxdeduction2 := taxdeduction1 + (grosspay - 728.77) * taxrate2
      else
      begin
         taxdeduction2 := taxdeduction1 + (1150.68 - 728.77) * taxrate2;
         taxdeduction3 := taxdeduction2 + (grosspay - 1150.68) * taxrate3;
         caltaxdeduction := taxdeduction1;
         caltaxdeduction := taxdeduction2;
         caltaxdeduction := taxdeduction3;
      end;
      end;
    end;

begin
   clrscr;
repeat
      write('Enter the hourly pay rate: ');
      {$I-}
      readln(payrate);
      {$I+}
      errorcode := IOResult;
         if errorcode <> 0 then
            begin
               sound(1000);
               delay(100);
               nosound;
            end;
   until errorcode = 0;

   repeat
      write('Enter the hours worked this week: ');
      {$I-}
      readln(workedhours);
      {$I+}
      errorcode := IOResult;
         if errorcode <> 0 then
            begin
               sound(1000);
               delay(100);
               nosound;
            end;
   until errorcode = 0;
   writeln;



   writeln('Current employee is: ', empname);
   writeln('Employee hourly pay rate is: $', payrate:2:2);
   writeln('The hours the employee worked this week is: ', workedhours:2:2);
   writeln('Employee grosspay for this week is: $', calgrosspay(workedhours, payrate):2:2);
   writeln;
   writeln;
   writeln('19.5% tax deduction of the first $728.77 equals S', caltaxdeduction(grosspay):2:2);
   writeln;
   writeln;
   writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction of');
   writeln('anything above that but below $1150.68 equals $', caltaxdeduction(grosspay):2:2);
   writeln;
   writeln;
   writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction of');
   writeln(' anything above that but below $1150.68 and a 39% deduction of anything');
   writeln('above $1150.68 equals $' , caltaxdeduction(grosspay):2:2);
   writeln;
   writeln;
   writeln('Press ENTER to exit the program');
   readln;
end.


Report
Re: How can I place this in a function? Posted by zibadian on 25 Mar 2004 at 10:21 PM
: Hi,
:
: I got the program compiling succesfully now too. I don't what the problem was. Perhaps one of the compilers on the computer.
: I have also decided to put the tax calculations into a function.
: My question is, how can I make the output print every tax deduction amount after each deduction?
: Currently it displays the first tax deduction for all three. It's probably obvious that it shouldn't be there.
: But where do the other 2 taxdeduction results go?
:
: Further help is appreciated
:
:
: 
: uses
:    crt;
: 
: const
:    normalhours = 40;
:    taxrate1 = 0.195;
:    taxrate2 = 0.33;
:    taxrate3 = 0.39;
: 
: var
:    empname : string[20];
:    payrate , errorcode : real;
:    workedhours , overtimehours , errorcode2 : real;
:    grosspay : real;
:    taxdeduction1 , taxdeduction2, taxdeduction3 : real;
: 
: 
: function calgrosspay(workedhours, payrate: real): real;
:    var
:       paidhours, premiumhours : real;
: 
:    begin
:       overtimehours := workedhours - normalhours;
:          if overtimehours <= 0 then
:          begin
:             paidhours := workedhours;
:          end
:          else if overtimehours > 0 then
:          begin
:             premiumhours := overtimehours * payrate * 1.5;
:          end;
: 
:          paidhours := normalhours * payrate;
:          grosspay := premiumhours + paidhours;
:          calgrosspay := grosspay;
:    end;
: 
:    function caltaxdeduction(grosspay: real): real;
:    begin
:       if grosspay <= 728.77 then
:          taxdeduction1 := grosspay * taxrate1
:       else
:       begin
:          taxdeduction1 := 728.77 * taxrate1;
:       if grosspay <= 1150.68 then
:          taxdeduction2 := taxdeduction1 + (grosspay - 728.77) * taxrate2
:       else
:       begin
:          taxdeduction2 := taxdeduction1 + (1150.68 - 728.77) * taxrate2;
:          taxdeduction3 := taxdeduction2 + (grosspay - 1150.68) * taxrate3;
:          caltaxdeduction := taxdeduction1;
:          caltaxdeduction := taxdeduction2;
:          caltaxdeduction := taxdeduction3;
:       end;
:       end;
:     end;
: 
: begin
:    clrscr;
: repeat
:       write('Enter the hourly pay rate: ');
:       {$I-}
:       readln(payrate);
:       {$I+}
:       errorcode := IOResult;
:          if errorcode <> 0 then
:             begin
:                sound(1000);
:                delay(100);
:                nosound;
:             end;
:    until errorcode = 0;
: 
:    repeat
:       write('Enter the hours worked this week: ');
:       {$I-}
:       readln(workedhours);
:       {$I+}
:       errorcode := IOResult;
:          if errorcode <> 0 then
:             begin
:                sound(1000);
:                delay(100);
:                nosound;
:             end;
:    until errorcode = 0;
:    writeln;
: 
: 
: 
:    writeln('Current employee is: ', empname);
:    writeln('Employee hourly pay rate is: $', payrate:2:2);
:    writeln('The hours the employee worked this week is: ', workedhours:2:2);
:    writeln('Employee grosspay for this week is: $', calgrosspay(workedhours, payrate):2:2);
:    writeln;
:    writeln;
:    writeln('19.5% tax deduction of the first $728.77 equals S', caltaxdeduction(grosspay):2:2);
:    writeln;
:    writeln;
:    writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction of');
:    writeln('anything above that but below $1150.68 equals $', caltaxdeduction(grosspay):2:2);
:    writeln;
:    writeln;
:    writeln('The 19.5% tax deduction of the first $728.77 plus a 33% tax deduction of');
:    writeln(' anything above that but below $1150.68 and a 39% deduction of anything');
:    writeln('above $1150.68 equals $' , caltaxdeduction(grosspay):2:2);
:    writeln;
:    writeln;
:    writeln('Press ENTER to exit the program');
:    readln;
: end.
: 

:
A function can only return 1 result. If you want return more results, you either need to split the function into smaller functions (in this case 1 for each tax deduction); or you can combine the result into either an array or a record; or you need to use a procedure with variable parameters.
I would advice you to make 1 function per tax deduction. Hint: you can call a function from within another function, if the former is defined before the latter.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.