> Any pascal coders? I need help with some code.?

Any pascal coders? I need help with some code.?

Posted at: 2014-12-18 
if (hours<0) or (hours>60) then writeln('Please enter hours worked properly.') else

if (hours>0) and (hours<60) then writeln('You''ve said that you have worked ', hours,' hours.');

You do NOT have to explicitly state the else condition. The else covers everything that isn't covered with the if. Was your intention to leave out a message if the user typed in 0 or 60? You are testing for less than and for greater than but you excluded the condition when it equals zero.or 60. But, if you just say else it will work:

So, use

if (hours<0) or (hours>60) then writeln('Please enter hours worked properly.')

else writeln('You''ve said that you have worked ', hours,' hours.');

if hours>40 then extrapay:=(hours-40)*(hrate*1.5);

if hours>40 then sum:= extrapay + (40-(hours*hrate)) else

If you want both assignment statements to be executed when hours > 40 then use

if hours>40 then begin

..... extrapay:= (hours - 40) * (hrate * 1.5);

..... sum:= extrapay + (40 - (hours * hrate));

end

Note: The leading dots to show indentation. Y!A removes leading blanks.

waitaminute. Shouldn't sum:= (extrapay + 40*hrate)? 40-hours is a negative number. It's 40 hours at hrate and hours-40 at hrate*1.5

So I'm doing exercises in Pascal and here is the brief of one -

4.10 - Write a program that asks the user for the number of hours worked this

week and their hourly rate of pay. The program is to calculate the gross

pay. If the number of hours worked is greater than 40, the extra hours

are paid at 1.5 times the rate. The program should display an error

message if the number of hours worked is not in the range between

0-60.

My code currently looks like this and isn't working properly -

uses

System.SysUtils;

var hours: integer;

hrate: integer;

extrapay : real;

sum : real;

begin

Writeln('Please enter the hours you worked this week between 0 and 60.');

readln(hours);

if (hours<0) or (hours>60) then writeln('Please enter hours worked properly.') else

if (hours>0) and (hours<60) then writeln('You''ve said that you have worked ', hours,' hours.');

writeln('Please write your hourly rate:');

readln(hrate);

writeln('You''ve said that your hourly rate is ', hrate, ' pounds');

if hours>40 then extrapay:=(hours-40)*(hrate*1.5);

if hours>40 then sum:= extrapay + (40-(hours*hrate)) else

if hours<=40 then sum:=(hours*hrate);

writeln('Your gross pay is ', sum:3:2, 'pounds');

readln;

end.

Hours without overtime works but I am so confused on what to do when I have to calculate the gross pay for hours below 40 and then calculate overtime pay over 40 hours, help!