0% found this document useful (0 votes)
37 views12 pages

C If&While

The document describes how to calculate employee pay based on hours worked using an if-then-else statement in C#. It states that if the number of hours worked is less than 41, pay is calculated as hours times rate, otherwise pay is calculated as 40 times rate plus overtime hours times 1.5 times the rate. It also explains that a Boolean expression is used to evaluate whether the condition is true or false, and the corresponding block of code after the if or else is executed.

Uploaded by

midowakil
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views12 pages

C If&While

The document describes how to calculate employee pay based on hours worked using an if-then-else statement in C#. It states that if the number of hours worked is less than 41, pay is calculated as hours times rate, otherwise pay is calculated as 40 times rate plus overtime hours times 1.5 times the rate. It also explains that a Boolean expression is used to evaluate whether the condition is true or false, and the corresponding block of code after the if or else is executed.

Uploaded by

midowakil
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

In English,

If the number of hours is less than 41, then the pay equals hours * rate, otherwise, the pay equals 40 * rate + overtime hours * rate*1.5

In English, and in C#
If if

In English, and in C#
If the number of hours is less than 41, if (hours<41)

In English, and in C#
If the number of hours is less than 41, then pay equals hours * rate if (hours<41) pay=hours*rate;

In English, and in C#
If the number of hours is less than 41, then pay equals hours * rate, otherwise, if (hours<41) pay=hours*rate; else

In English, and in C#
If the number of hours is less than 41, then pay equals hours * rate, otherwise, the pay equals 40 * rate + overtime hours * rate*1.5 if (hours<41) pay=hours*rate; else pay = 40*rate + overtime*rate*1.5;

IF THEN ELSE, in C#
if (hours<41) pay=hours*rate; else pay = 40*rate + overtime*rate*1.5; hours<41 is a Boolean expression A Boolean expression evaluates to either true or false. If it is true, then run the statement after it , else, run the statement after else

Loops

We need to repeat steps!

Loops

We need to repeat steps:

How many repetitions? Who decides the number of repetitions? User or Programmer?

The while statement

while (Boolean Expression)

Statement

The while statement


while (Boolean Expression)
Statement

OR
while (Boolean Expression)
{Statements}

The for statement

for (Initialization; Condition Expression ; Update)

Statement

Initialization: Executed before the loop.

count=0

Condition Expression: Evaluated before each repetition.

count<Max

Update: Executed after each repetition.

count++

You might also like