Program Problems - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Program Problems

ElCoolioElCoolio Posts: 2Member
Hi all, for an assignment ive gotta create a payroll program using TB7. The programs done but im having slight problems with the loop. After every payroll thats done it asks the user if they want to make another, which is all good but if the user selects yes when the program restarts it misses out asking for the employees name. Ive tried everything im capable of but cant solve it. IF neone could help that would be great.

program Wages;

uses crt;

var

{ENTERANCE MOVING TEXT AND MAIN MENU}
movetext : byte; {Number of times to move text horizontally}
xy : byte; {Moves text one space horiontally}
menuchoice : byte; {Used when choosing an option at the main menu}


{NUMERIC VARIABLES}
empname : string; {Empyees number}
hours : byte; {Number of hours worked}
pay : real; {Hourly Pay for employee}
overtime : real; {Overtime pay for employee}
grosspay : real; {The gross pay}
sub1 : real; {Part1 - Working out overtime}
sub2 : real; {Part2 - Working out overtime}
before40 : real; {When working over time - pay for first 40 hours}
taxcode : integer; {Empoyees tax code}
taxallowance : real; {Tax allowance - taxcode*10/52 = weekly tax}
taxpaid : real; {Amount of tax paid this week}
natins : real; {National insurance - 10% of gross pay}
netpay : real; {Employees Net Pay}
errorcheck : byte; {Used when checking for errors}

morepayslips : char; {Used when asking user if they want to create another payslip}

begin

{Enterance Screen}
clrscr;
for xy := 1 to 32 do {For every xy value between 1 and 32 do the following instructions}
begin
gotoxy(xy,13); {Moves text but uses the value of xy as horizontal value}
textcolor(red);
write(' Lancombe and More Payroll Processing');
xy := xy + 1; {Adds 1 to xy so next time the text is moved one place horizontally}
gotoxy(25,20);
textcolor(white);
writeln('Program made by Carl Knowles'); {Maker of Program}
delay(100);
end;

clrscr;
textcolor(red+blink);
gotoxy(22,13);
writeln('Lancombe and More Payroll Processing'); {Program title}
textcolor(white);
gotoxy(25,20);
writeln('Press Enter Button To Continue'); {Asks user for input before program continues}
readln;

repeat
empname := ''; {Start resetting values}
hours := 0;
pay := 0;
overtime := 0;
grosspay := 0;
sub1 := 0;
sub2 := 0;
before40 := 0;
taxcode := 0;
taxallowance :=0;
taxpaid := 0;
natins := 0;
netpay := 0; {End of resetting values}
clrscr;
textcolor(red+blink);
gotoxy(22,2);
writeln('ENTER EMPLOYEE INFORMATION'); {Employee Information Title}
textcolor(white);
gotoxy(18,5);
write('Enter Employee Name : '); read(empname); {Asks for employee name and stores in in variable empname}
gotoxy(21,8);
write('Employee Hourly Pay : '); read(pay); {Asked for employees hourly wage}
gotoxy(22,11);
write('No of Hours Worked? : '); read(hours); {Asks for number of hours worked}

repeat

errorcheck := 0; {Resets errorcode to 0}
gotoxy(20,14);
write('Enter Employee Tax Code : '); read(taxcode); {Asks user to input tax code}

if (taxcode < 100) or (taxcode > 999) then errorcheck := 1; {Checks if the tax code is a valid number}

until errorcheck = 0;

writeln;
readln;

if hours <= 40 then {Total pay when no overtime is worked}

begin

grosspay := hours * pay; {Calculates gross pay}

end;

if hours > 40 then {Total when working overtime}

begin

overtime := pay * 1.5; {Works out the overtimes hourly rate}
sub1 := hours - 40; {Working out number of overtime hours}
sub2 := sub1 * overtime; {How much paid for overtime}
before40 := hours * pay; {Wage for normal 35 hours}
grosspay := sub2 + before40; {Adding up overtime and nomral wage}
end;

{Working out Results for payslip}
natins := grosspay / 10; {Caclulates national insurance contribution}
taxallowance := (taxcode*10/52); {Calculates tax allowance for 1 week}
taxpaid := (grosspay-taxallowance)/5;

if taxpaid < 0 then

begin
taxpaid := 0 {This is so that the amount of tax being paid is a negative value}
end;

netpay := grosspay - natins - taxpaid; {Calculates employees net pay by subtracting nation insurance and tax paid}

{Prints Payslip}
clrscr;
textcolor(red+blink);
gotoxy(30,2);
writeln('EMPLOYEE PAYSLIP'); {Employee Information Title}
textcolor(white);
gotoxy(24,5);
writeln('Employee Name : ', empname); {Prints the employees name}
gotoxy(28,8);
writeln('Gross Pay : ', grosspay :6:2); {Prints gross pay}
gotoxy(26,11);
writeln('Tax Allowance : ', taxallowance :6:2); {Prints tax allowance}
gotoxy(25,14);
writeln('Total Tax Paid : ', taxpaid :6:2); {Prints total tax paid}
gotoxy(23,17);
writeln('National Insurance : ', natins :6:2); {Prints national insurance contribution}
gotoxy(29,20);
writeln('Net Pay : ', netpay :6:2); {Prints employees net pay}

repeat

gotoxy(13,25);
write('Would you like to create another payslip? (Y/N) : '); read(morepayslips);
{Ask user if they want to create another payslip}
morepayslips := upcase(morepayslips);

until (morepayslips='Y') or (morepayslips='N');

until morepayslips = 'N'; {Close loop if the user chooses to not create more payslips}

end.

Comments

  • bpajkbpajk Posts: 156Member
    I have made some slight changes in you're code, I hope you don't mind. The problem was the read() procedure. I have replaced it with readln(). The read procedure doesn't catch the ENTER key which disturbed you're Employee name input. And use CODE tags next time.

    [CODE]
    program Wages;
    uses crt;
    var

    {ENTERANCE MOVING TEXT AND MAIN MENU}
    movetext : byte; {Number of times to move text horizontally} {not used}
    xy : byte; {Moves text one space horiontally}
    menuchoice : byte; {Used when choosing an option at the main menu} {not used}

    {NUMERIC VARIABLES}
    empname : string; {Empyees number}
    hours : byte; {Number of hours worked}
    pay : real; {Hourly Pay for employee}
    overtime : real; {Overtime pay for employee}
    grosspay : real; {The gross pay}
    sub1 : real; {Part1 - Working out overtime}
    sub2 : real; {Part2 - Working out overtime}
    before40 : real; {When working over time - pay for first 40 hours}
    taxcode : integer; {Empoyees tax code}
    taxallowance : real; {Tax allowance - taxcode*10/52 = weekly tax}
    taxpaid : real; {Amount of tax paid this week}
    natins : real; {National insurance - 10% of gross pay}
    netpay : real; {Employees Net Pay}
    errorcheck : byte; {Used when checking for errors}

    morepayslips : char; {Used when asking user if they want to create another payslip}

    begin
    {Enterance Screen}
    clrscr;
    for xy := 1 to 32 do {For every xy value between 1 and 32 do the following instructions}
    begin
    gotoxy(xy,13); {Moves text but uses the value of xy as horizontal value}
    textcolor(red);
    write(' Lancombe and More Payroll Processing');
    xy := xy + 1; {Adds 1 to xy so next time the text is moved one place horizontally}
    gotoxy(25,20);
    textcolor(white);
    writeln('Program made by Carl Knowles'); {Maker of Program}
    delay(100)
    end;
    clrscr;
    textcolor(red+blink);
    gotoxy(22,13);
    writeln('Lancombe and More Payroll Processing'); {Program title}
    textcolor(white);
    gotoxy(25,20);
    writeln('Press Enter Button To Continue'); {Asks user for input before program continues}
    readln;
    repeat
    empname := ''; {Start resetting values}
    hours := 0;
    pay := 0;
    overtime := 0;
    grosspay := 0;
    sub1 := 0;
    sub2 := 0;
    before40 := 0;
    taxcode := 0;
    taxallowance :=0;
    taxpaid := 0;
    natins := 0;
    netpay := 0; {End of resetting values}
    clrscr;
    textcolor(red+blink);
    gotoxy(22,2);
    writeln('ENTER EMPLOYEE INFORMATION'); {Employee Information Title}
    textcolor(white);
    gotoxy(18,5);
    write('Enter Employee Name : '); read(empname); {Asks for employee name and stores in in variable empname}
    gotoxy(21,8);
    write('Employee Hourly Pay : o'); read(pay); {Asked for employees hourly wage}
    gotoxy(22,11);
    write('No of Hours Worked? : '); read(hours); {Asks for number of hours worked}
    repeat
    errorcheck := 0; {Resets errorcode to 0}
    gotoxy(20,14);
    write('Enter Employee Tax Code : '); read(taxcode); {Asks user to input tax code}
    if (taxcode < 100) or (taxcode > 999) then
    errorcheck := 1 {Checks if the tax code is a valid number}
    until errorcheck = 0;
    writeln;
    readln;
    if hours <= 40 then {Total pay when no overtime is worked}
    grosspay := hours * pay; {Calculates gross pay}
    if hours > 40 then {Total when working overtime}
    begin
    overtime := pay * 1.5; {Works out the overtimes hourly rate}
    sub1 := hours - 40; {Working out number of overtime hours}
    sub2 := sub1 * overtime; {How much paid for overtime}
    before40 := hours * pay; {Wage for normal 35 hours}
    grosspay := sub2 + before40 {Adding up overtime and nomral wage}
    end;
    {Working out Results for payslip}
    natins := grosspay / 10; {Caclulates national insurance contribution}
    taxallowance := (taxcode*10/52); {Calculates tax allowance for 1 week}
    taxpaid := (grosspay-taxallowance)/5;
    if taxpaid < 0 then
    taxpaid := 0; {This is so that the amount of tax being paid is a negative value}
    netpay := grosspay - natins - taxpaid; {Calculates employees net pay by subtracting nation insurance and tax paid}
    {Prints Payslip}
    clrscr;
    textcolor(red+blink);
    gotoxy(30,2);
    writeln('EMPLOYEE PAYSLIP'); {Employee Information Title}
    textcolor(white);
    gotoxy(24,5);
    writeln('Employee Name : ', empname); {Prints the employees name}
    gotoxy(28,8);
    writeln('Gross Pay : o', grosspay :6:2); {Prints gross pay}
    gotoxy(26,11);
    writeln('Tax Allowance : o', taxallowance :6:2); {Prints tax allowance}
    gotoxy(25,14);
    writeln('Total Tax Paid : o', taxpaid :6:2); {Prints total tax paid}
    gotoxy(23,17);
    writeln('National Insurance : o', natins :6:2); {Prints national insurance contribution}
    gotoxy(29,20);
    writeln('Net Pay : o', netpay :6:2); {Prints employees net pay}
    repeat
    gotoxy(13,25);
    {You have to put ReadLn() instead of Read()}
    write('Would you like to create another payslip? (Y/N) : '); readln(morepayslips);
    {Ask user if they want to create another payslip}
    morepayslips := upcase(morepayslips)
    until (morepayslips='Y') or (morepayslips='N')
    until morepayslips = 'N' {Close loop if the user chooses to not create more payslips}
    end.
    [/CODE]
Sign In or Register to comment.