Introduction to Conditional Statements
Introduction to Conditional Statements
Fundamentals of Conditions
Introduction
A Boolean value is an item that holds a value as true or false.
Introduction to Boolean Operators
You can compare two items to find out whether they are equal, they are different, one is higher or lower than the other, or for any other reason you think is necessary. To do this, you can use an operator referred to as Boolean, a Boolean operator. You apply such an operator bwtween the items you want to compare. This can be illustrated as follows:
value-or-expression1 operator value-or-expression2
Here, each of the items is represented as value-or-expression.
Practical Learning: Introducing Conditions
printfn "FUN DEPARTMENT STORE" printfn "=======================================================" printfn "Item Preparation" printfn "-------------------------------------------------------" printfn "Enter the following pieces of information" printfn "-------------------------------------------------------" let discountRate = 75.00 printf "Item Name: " let itemName : string = stdin.ReadLine() printf "Original Price: " let originalPrice = float(stdin.ReadLine()) printf "Days in Store: " let daysInStore = int(stdin.ReadLine()) let discountAmount = originalPrice * discountRate / 100.00 let discountedPrice = originalPrice - discountAmount printfn "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" printfn "FUN DEPARTMENT STORE" printfn "=======================================================" printfn "Store Inventory" printfn "-------------------------------------------------------" printfn "Item Name: %s" itemName printfn "Original Price: %0.2f" originalPrice printfn "Days in Store: %i" daysInStore printfn "Discount Rate: %0.2f%c" discountRate '%' printfn "Discount Amount: %0.2f" discountAmount printfn "Discounted Price: %0.2f" discountedPrice printfn "======================================================="
FUN DEPARTMENT STORE ======================================================= Item Preparation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Item Name: Tulip Sleeved Sheath Dress Original Price: 89.95 Days in Store: 28 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ FUN DEPARTMENT STORE ======================================================= Store Inventory ------------------------------------------------------- Item Name: Tulip Sleeved Sheath Dress Original Price: 89.95 Days in Store: 28 Discount Rate: 75% Discount Amount: 67.46 Discounted Price: 22.49 ======================================================= Press any key to close this window . . .
Fundamentals of Boolean Values
Introduction
A value is said to be Boolean if it is true or it is false. In fact, the two available Boolean values are true and false.
To declare a Boolean variable, use the let keyword and assign true or false to the variable. Here is an example of declaring a Boolean variable:
let drinkingUnderAge = true
Of course, you can end the declaration with a semicolon or not.
A Boolean Data Type
To support Boolean values, the F# language provides a data type named bool. You can use when declaring Boolean variable. Here is an example:
let driverIsSober : bool = true
Assigning a Logical Expression to a Boolean Variable
We saw that, to initialize or specify the value of a Boolean variable, you can assign a true or false value. A Boolean variable can also be initialized with a Boolean expression. This would be done as follows:
let variable = operand1 Boolean-operator operand2;
To make your code easy to read, you should include the logical expression in parentheses. This can be done as follows:
let variable = (operand1 Boolean-operator operand2);
Introduction to Conditions
Introduction
As mentioned already, a comparison is used to establish the logical relationship between two values, a variable and a value, or two variables. There are various operators available to perform such comparisons.
To let you get the result of comparing two values, the F# language provides a keyword named if. The primary formula to use it is:
if variable-or-value1 operator variable-or-value2 then statement[;]
The if and the then keywords are required. The variable-or-value1 factor is an item on the left side of a Boolean operator. The variable-or-value2 factor is an item on the right side of a Boolean operator. The operator factor is a Boolean operator. After the then keyword, you should (must) specify what to do if the comparison produces a true result. You can end that statement with a semicolon or omit that semicolon.
If the statement is short, you can write it on the same line as the if...then line, as seen in the above formula. If the statement is long, you should write it on the next line.
Fundamentals of Logical Operators
To find out whether one value is lower than another, the operator to use <. Its formula is:
value1 < value2
This operation can be illustrated as follows:
Here is an example:
let yearlySalary = 36_000
let mutable employmentStatus = "Full-Time"
if yearlySalary < 40000 then
employmentStatus <- "Part-Time"
printfn "Employee Record"
printfn "-----------------------------"
printfn "Yearly Salary: %i" yearlySalary
printfn "Employment Status: %s" employmentStatus
printfn "============================="
This would produce:
Employee Record ----------------------------- Yearly Salary: 36000 Employment Status: Part-Time ============================= Press any key to close this window . . .
Practical Learning: Comparing for a Lesser Value
printfn "FUN DEPARTMENT STORE" printfn "=======================================================" printfn "Item Preparation" printfn "-------------------------------------------------------" printfn "Enter the following pieces of information" printfn "-------------------------------------------------------" let mutable discountRate = 75.00 printf "Item Name: " let itemName : string = stdin.ReadLine() printf "Original Price: " let originalPrice = float(stdin.ReadLine()) printf "Days in Store: " let daysInStore = int(stdin.ReadLine()) if daysInStore < 60 then discountRate <- 50 if daysInStore < 45 then discountRate <- 35 if daysInStore < 35 then discountRate <- 15 if daysInStore < 15 then discountRate <- 0 let discountAmount = originalPrice * discountRate / 100.00 let discountedPrice = originalPrice - discountAmount printfn "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" printfn "FUN DEPARTMENT STORE" printfn "=======================================================" printfn "Store Inventory" printfn "-------------------------------------------------------" printfn "Item Name: %s" itemName printfn "Original Price: %0.2f" originalPrice printfn "Days in Store: %i" daysInStore printfn "Discount Rate: %0.2f%c" discountRate '%' printfn "Discount Amount: %0.2f" discountAmount printfn "Discounted Price: %0.2f" discountedPrice printfn "======================================================="
FUN DEPARTMENT STORE ======================================================= Item Preparation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Item Name: Tulip Sleeved Sheath Dress Original Price: 89.95 Days in Store: 28 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ FUN DEPARTMENT STORE ======================================================= Store Inventory ------------------------------------------------------- Item Name: Tulip Sleeved Sheath Dress Original Price: 89.95 Days in Store: 28 Discount Rate: 15% Discount Amount: 13.49 Discounted Price: 76.46 ======================================================= Press any key to close this window . . .
FUN DEPARTMENT STORE ======================================================= Item Preparation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Item Name: Tulip Sleeved Sheath Dress Original Price: 89.95 Days in Store: 46 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ FUN DEPARTMENT STORE ======================================================= Store Inventory ------------------------------------------------------- Item Name: Tulip Sleeved Sheath Dress Original Price: 89.95 Days in Store: 46 Discount Rate: 50% Discount Amount: 44.98 Discounted Price: 44.98 ======================================================= Press any key to close this window . . .
printfn "FUN DEPARTMENT STORE" printfn "=======================================================" printfn "Payroll Preparation" printfn "-------------------------------------------------------" printfn "Enter the following pieces of information" printfn "-------------------------------------------------------" printfn "Employee Information" printfn "-------------------------------------------------------" printf "First Name: " let firstName : string = stdin.ReadLine() printf "Last Name: " let lastName : string = stdin.ReadLine() printf "Hourly Salary: " let hSalary : float = float(stdin.ReadLine()) printfn "-------------------------------------------------------" printfn "Time worked" printfn "-------------------------------------------------------" printf "Monday: " let mon : float = float(stdin.ReadLine()) printf "Tuesday: " let tue = float(stdin.ReadLine()) printf "Wednesday: " let wed = float(stdin.ReadLine()) printf "Thursday: " let thu = float(stdin.ReadLine()) printf "Friday: " let fri = float(stdin.ReadLine()) let timeWorked = mon + tue + wed + thu + fri let netPay = hSalary * timeWorked printfn "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+" printfn "FUN DEPARTMENT STORE" printfn "=======================================================" printfn "Payroll Evaluation" printfn "=======================================================" printfn "Employee Information" printfn "-------------------------------------------------------" printfn "Full Name: %s %s" firstName lastName printfn "Hourly Salary: %0.2f" hSalary printfn "=======================================================" printfn "Time Worked Summary" printfn "--------+---------+-----------+----------+-------------" printfn " Monday | Tuesday | Wednesday | Thursday | Friday" printfn "--------+---------+-----------+----------+-------------" printfn " %0.2f | %0.2f | %0.2f | %0.2f | %0.2f" mon tue wed thu fri printfn "========+=========+===========+==========+=============" printfn " Pay Summary" printfn "-------------------------------------------------------" printfn " Total Time: %0.2f" timeWorked printfn "-------------------------------------------------------" printfn " Net Pay: %0.2f" netPay printfn "======================================================="
First Name: | Michael |
Last Name: | Carlock |
Hourly Salary: | 28.25 |
Monday | 7 |
Tuesday: | 8 |
Wednesday: | 6.5 |
Thursday: | 8.5 |
Friday: | 6.5 |
FUN DEPARTMENT STORE ======================================================= Payroll Preparation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Employee Information ------------------------------------------------------- First Name: Michael Last Name: Carlock Hourly Salary: 28.25 ------------------------------------------------------- Time worked ------------------------------------------------------- Monday: 7 Tuesday: 8 Wednesday: 6.5 Thursday: 8.5 Friday: 6.5 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ FUN DEPARTMENT STORE ======================================================= Payroll Evaluation ======================================================= Employee Information ------------------------------------------------------- Full Name: Michael Carlock Hourly Salary: 28.25 ======================================================= Time Worked Summary --------+---------+-----------+----------+------------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+------------- 7.00 | 8.00 | 6.50 | 8.50 | 6.50 ========+=========+===========+==========+============= Pay Summary ------------------------------------------------------- Total Time: 36.50 ------------------------------------------------------- Net Pay: 1031.12 ======================================================= Press any key to close this window . . .
First Name: | Catherine |
Last Name: | Busbey |
Hourly Salary: | 24.37 |
Monday | 9.50 |
Tuesday: | 8 |
Wednesday: | 10.50 |
Thursday: | 9 |
Friday: | 10.50 |
FUN DEPARTMENT STORE ======================================================= Payroll Preparation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Employee Information ------------------------------------------------------- First Name: Catherine Last Name: Busbey Hourly Salary: 24.37 ------------------------------------------------------- Time worked ------------------------------------------------------- Monday: 9.5 Tuesday: 8 Wednesday: 10.5 Thursday: 9 Friday: 10.5 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ FUN DEPARTMENT STORE ======================================================= Payroll Evaluation ======================================================= Employee Information ------------------------------------------------------- Full Name: Catherine Busbey Hourly Salary: 24.37 ======================================================= Time Worked Summary --------+---------+-----------+----------+------------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+------------- 9.50 | 8.00 | 10.50 | 9.00 | 10.50 ========+=========+===========+==========+============= Pay Summary ------------------------------------------------------- Total Time: 47.50 ------------------------------------------------------- Net Pay: 1157.58 ======================================================= Press any key to close this window . . .
A Value Greater Than Another: >
To find out if one value is greater than the other, the operator to use is >. Its formula is:
value1 > value2
Both operands, in this case value1 and value2, can be variables or the left operand can be a variable while the right operand is a constant. If the value on the left of the > operator is greater than the value on the right side or a constant, the comparison produces a True. Otherwise, the comparison renders False. This operation can be illustrated as follows:
Here is an example:
let yearlySalary = 42_000
let mutable employmentStatus = "Part-Time"
if yearlySalary > 40000 then
employmentStatus <- "Full-Time"
printfn "Employee Record"
printfn "-----------------------------"
printfn "Yearly Salary: %i" yearlySalary
printfn "Employment Status: %s" employmentStatus
printfn "============================="
This would produce:
Employee Record ----------------------------- Yearly Salary: 42000 Employment Status: Full-Time ============================= Press any key to close this window . . .
Practical Learning: Finding Out Whether a Value is Greater Than Another
printfn "FUN DEPARTMENT STORE"
printfn "======================================================="
printfn "Payroll Preparation"
printfn "-------------------------------------------------------"
printfn "Enter the following pieces of information"
printfn "-------------------------------------------------------"
printfn "Employee Information"
printfn "-------------------------------------------------------"
printf "First Name: "
let firstName : string = stdin.ReadLine()
printf "Last Name: "
let lastName : string = stdin.ReadLine()
printf "Hourly Salary: "
let hSalary : float = float(stdin.ReadLine())
printfn "-------------------------------------------------------"
printfn "Time worked"
printfn "-------------------------------------------------------"
printf "Monday: "
let mon : float = float(stdin.ReadLine())
printf "Tuesday: "
let tue = float(stdin.ReadLine())
printf "Wednesday: "
let wed = float(stdin.ReadLine())
printf "Thursday: "
let thu = float(stdin.ReadLine())
printf "Friday: "
let fri = float(stdin.ReadLine())
let timeWorked = mon + tue + wed + thu + fri
let mutable regTime = timeWorked
let mutable overtime = 0.00
let mutable overPay = 0.00
let mutable regPay = hSalary * timeWorked
if timeWorked > 40.00 then
regTime <- 40.00
regPay <- hSalary * 40.00
overtime <- timeWorked - 40.00
overPay <- hSalary * 1.50 * overtime
let netPay : float = regPay + overPay
printfn "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+"
printfn "FUN DEPARTMENT STORE"
printfn "======================================================="
printfn "Payroll Evaluation"
printfn "======================================================="
printfn "Employee Information"
printfn "-------------------------------------------------------"
printfn "Full Name: %s %s" firstName lastName
printfn "Hourly Salary: %0.2f" hSalary
printfn "======================================================="
printfn "Time Worked Summary"
printfn "--------+---------+-----------+----------+-------------"
printfn " Monday | Tuesday | Wednesday | Thursday | Friday"
printfn "--------+---------+-----------+----------+-------------"
printfn " %0.2f | %0.2f | %0.2f | %0.2f | %0.2f" mon tue wed thu fri
printfn "========+=========+===========+==========+============="
printfn " Pay Summary"
printfn "-------------------------------------------------------"
printfn " Time Pay"
printfn "-------------------------------------------------------"
printfn " Regular: %0.2f %0.2f" regTime regPay
printfn "-------------------------------------------------------"
printfn " Overtime: %0.2f %0.2f" overtime overPay
printfn "======================================================="
printfn " Net Pay: %0.2f" netPay
printfn "======================================================="
FUN DEPARTMENT STORE ======================================================= Payroll Preparation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Employee Information ------------------------------------------------------- First Name: Michael Last Name: Carlock Hourly Salary: 28.25 ------------------------------------------------------- Time worked ------------------------------------------------------- Monday: 7 Tuesday: 8 Wednesday: 6.5 Thursday: 8.5 Friday: 6.5 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ FUN DEPARTMENT STORE ======================================================= Payroll Evaluation ======================================================= Employee Information ------------------------------------------------------- Full Name: Michael Carlock Hourly Salary: 28.25 ======================================================= Time Worked Summary --------+---------+-----------+----------+------------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+------------- 7.00 | 8.00 | 6.50 | 8.50 | 6.50 ========+=========+===========+==========+============= Pay Summary ------------------------------------------------------- Time Pay ------------------------------------------------------- Regular: 36.50 1031.12 ------------------------------------------------------- Overtime: 0.00 0.00 ======================================================= Net Pay: 1031.12 ======================================================= Press any key to close this window . . .
FUN DEPARTMENT STORE ======================================================= Payroll Preparation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Employee Information ------------------------------------------------------- First Name: Catherine Last Name: Busbey Hourly Salary: 24.37 ------------------------------------------------------- Time worked ------------------------------------------------------- Monday: 9.5 Tuesday: 8 Wednesday: 10.5 Thursday: 9 Friday: 10.5 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ FUN DEPARTMENT STORE ======================================================= Payroll Evaluation ======================================================= Employee Information ------------------------------------------------------- Full Name: Catherine Busbey Hourly Salary: 24.37 ======================================================= Time Worked Summary --------+---------+-----------+----------+------------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+------------- 9.50 | 8.00 | 10.50 | 9.00 | 10.50 ========+=========+===========+==========+============= Pay Summary ------------------------------------------------------- Time Pay ------------------------------------------------------- Regular: 40.00 974.80 ------------------------------------------------------- Overtime: 7.50 274.16 ======================================================= Net Pay: 1248.96 ======================================================= Press any key to close this window . . .
To compare two variables for equality, you can apply the = operator. The formula to use it is:
value1 = value2
The equality operation is used to find out whether two variables (or one variable and a value) hold the same value. The operation can be illustrated as follows:
Here is an example:
let mutable startingSalary = 34_000
let employmentStatus = "Full-Time"
if employmentStatus > "Part-Time" then
startingSalary <- 40_000
printfn "Employee Record"
printfn "----------------------------------"
printfn "Employment Status: %s" employmentStatus
printfn "Starting Yearly Salary: %i" startingSalary
printfn "=================================="
This would produce:
Employee Record ---------------------------------- Employment Status: Full-Time Starting Yearly Salary: 34000 ================================== Press any key to close this window . . .
Logical Difference
The opposite of the logical equality is to find out whether two values are different. The operator to do this is a combination of < and >, as in <>. It can be illustrated as follows:
A typical Boolean expression involves two operands separated by a logical operator. Both operands must be of the same type. These rules apply to the logical difference. It can be used on numbers, strings, etc. If both operands are different, the operation produces a true result. If they are the exact same, the operation produces False.
The <> operator can be used the same way as the equality operator (=) as long as you keep in mind that <> is the opposite of =. Here is an example:
let mutable certification = 'y';
let mutable employmentStatus = "Hired";
printf "Do you hold a C# certification (y = Yes): "
certification <- char(stdin.ReadLine())
if certification <> 'y' then
employmentStatus <- "This employment requires C# certification. We will get back to you."
printfn "=================================================================================================="
printfn "Employment Verification"
printfn "--------------------------------------------------------------------------------------------------"
printfn "Candition holds certification: %c" certification
printfn "Decision Status: %s" employmentStatus
printfn "=================================================================================================="
Here is an example of running the program:
Do you hold a C# certification (y = Yes): y ================================================================================================== Employment Verification -------------------------------------------------------------------------------------------------- Candition holds certification: y Decision Status: Hired ================================================================================================== Press any key to close this window . . .
Here is another example of running the program:
Do you hold a C# certification (y = Yes): N ================================================================================================== Employment Verification -------------------------------------------------------------------------------------------------- Candition holds certification: N Decision Status: This employment requires C# certification. We will get back to you. ================================================================================================== Press any key to close this window . . .
The Equality (=) and the Less Than (<) operations can be combined to compare two values. This allows you to know if two values are the same or if the first value is lower than the second value. The operator used is <=. Its formula is:
value1 <= value2
When performing the <= operation, if both value1 and value2 hold the same value, the result is True. If the left operand, in this case value1, holds a value lower than the second operand, in this case value2, the result is still True. The <= operation can be illustrated as follows:
Here is an example that uses the <= operator:
let originalPrice = 124.50
let mutable discountRate = 35 // %
let mutable numberOfDaysInStore = 75
if numberOfDaysInStore <= 45 then
discountRate <- 25
let mutable discountAmount = originalPrice * float discountRate / float 100
let mutable markedPrice = originalPrice - discountAmount
printfn "Fun Department Store"
printfn "----------------------------------"
printfn $"Original Price: {originalPrice:f}"
printfn $"Days in Store: {numberOfDaysInStore}"
printfn "Discount Rate: %i%c" discountRate '%'
printfn $"Discount Amount: {discountAmount:n}"
printfn $"Marked Price: {markedPrice:n}"
printfn "=================================="
numberOfDaysInStore <- 22
if numberOfDaysInStore <= 45 then
discountRate <- 25
discountAmount <- originalPrice * float discountRate / float 100
markedPrice <- originalPrice - discountAmount
printfn "Fun Department Store"
printfn "---------------------------------"
printfn $"Original Price: {originalPrice:N}"
printfn $"Days in Store: {numberOfDaysInStore}"
printfn "Discount Rate: %i%c" discountRate '%'
printfn $"Discount Amount: {discountAmount:N}"
printfn $"Marked Price: {markedPrice:N}"
printfn "=================================="
This would produce:
Fun Department Store ---------------------------------- Original Price: 124.50 Days in Store: 75 Discount Rate: 35% Discount Amount: 43.58 Marked Price: 80.92 ================================== Fun Department Store --------------------------------- Original Price: 124.50 Days in Store: 22 Discount Rate: 25% Discount Amount: 31.12 Marked Price: 93.38 ================================== Press any key to close this window . . .
Practical Learning: Comparing for a Lesser or Equal Value
printfn "FUN DEPARTMENT STORE"
printfn "======================================================="
printfn "Payroll Preparation"
printfn "-------------------------------------------------------"
printfn "Enter the following pieces of information"
printfn "-------------------------------------------------------"
printfn "Employee Information"
printfn "-------------------------------------------------------"
printf "First Name: "
let firstName : string = stdin.ReadLine()
printf "Last Name: "
let lastName : string = stdin.ReadLine()
printf "Hourly Salary: "
let hSalary : float = float(stdin.ReadLine())
printfn "-------------------------------------------------------"
printfn "Time worked"
printfn "-------------------------------------------------------"
printf "Monday: "
let mon : float = float(stdin.ReadLine())
printf "Tuesday: "
let tue = float(stdin.ReadLine())
printf "Wednesday: "
let wed = float(stdin.ReadLine())
printf "Thursday: "
let thu = float(stdin.ReadLine())
printf "Friday: "
let fri = float(stdin.ReadLine())
let timeWorked = mon + tue + wed + thu + fri
let mutable regTime = 40.00
let mutable overtime = timeWorked - 40.00
let mutable regPay = hSalary * 40.00
let mutable overPay = hSalary * 1.50 * overtime
if timeWorked <= 40.00 then
begin
regTime <- timeWorked
regPay <- hSalary * timeWorked
overtime <- 0.00
overPay <- 0.00
end
let netPay : float = regPay + overPay
printfn "+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+"
printfn "FUN DEPARTMENT STORE"
printfn "======================================================="
printfn "Payroll Evaluation"
printfn "======================================================="
printfn "Employee Information"
printfn "-------------------------------------------------------"
printfn "Full Name: %s %s" firstName lastName
printfn "Hourly Salary: %0.2f" hSalary
printfn "======================================================="
printfn "Time Worked Summary"
printfn "--------+---------+-----------+----------+-------------"
printfn " Monday | Tuesday | Wednesday | Thursday | Friday"
printfn "--------+---------+-----------+----------+-------------"
printfn " %0.2f | %0.2f | %0.2f | %0.2f | %0.2f" mon tue wed thu fri
printfn "========+=========+===========+==========+============="
printfn " Pay Summary"
printfn "-------------------------------------------------------"
printfn " Time Pay"
printfn "-------------------------------------------------------"
printfn " Regular: %0.2f %0.2f" regTime regPay
printfn "-------------------------------------------------------"
printfn " Overtime: %0.2f %0.2f" overtime overPay
printfn "======================================================="
printfn " Net Pay: %0.2f" netPay
printfn "======================================================="
FUN DEPARTMENT STORE ======================================================= Payroll Preparation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Employee Information First Name: Michael Last Name: Carlock Hourly Salary: 28.25 ------------------------------------------------------- Time worked ------------------------------------------------------- Monday: 7 Tuesday: 8 Wednesday: 6.5 Thursday: 8.5 Friday: 6.5 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ FUN DEPARTMENT STORE ======================================================= Payroll Evaluation ======================================================= Employee Information ------------------------------------------------------- Full Name: Michael Carlock Hourly Salary: 28.25 ======================================================= Work Preparation --------+---------+-----------+----------+------------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+------------- 7.00 8.00 6.50 8.50 6.50 ======================================================= Pay Summary ------------------------------------------------------- Time Pay ------------------------------------------------------- Regular: 36.50 1031.12 ------------------------------------------------------- Overtime: 0.00 0.00 ======================================================= Net Pay: 1031.12 ======================================================= Press any key to close this window . . .
FUN DEPARTMENT STORE ======================================================= Payroll Preparation ------------------------------------------------------- Enter the following pieces of information ------------------------------------------------------- Employee Information First Name: Catherine Last Name: Busbey Hourly Salary: 24.37 ------------------------------------------------------- Time worked ------------------------------------------------------- Monday: 9.5 Tuesday: 8 Wednesday: 10.5 Thursday: 9 Friday: 10.5 +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ FUN DEPARTMENT STORE ======================================================= Payroll Evaluation ======================================================= Employee Information ------------------------------------------------------- Full Name: Catherine Busbey Hourly Salary: 24.37 ======================================================= Work Preparation --------+---------+-----------+----------+------------- Monday | Tuesday | Wednesday | Thursday | Friday --------+---------+-----------+----------+------------- 9.50 8.00 10.50 9.00 10.50 ======================================================= Pay Summary ------------------------------------------------------- Time Pay ------------------------------------------------------- Regular: 40.00 974.80 ------------------------------------------------------- Overtime: 7.50 274.16 ======================================================= Net Pay: 1248.96 ======================================================= Press any key to close this window . . .
printfn "===================================================================" printfn "Machine Depreciation Evaluation - Straight-Line Method" printfn "===================================================================" printfn "Enter the values to evaluation the depreciation of the machine" printf "Machine Cost: " let machineCost = float(stdin.ReadLine()) printf "Salvage Value: " let salvageValue = float(stdin.ReadLine()) printf "Estimated Life: " let estimatedLife = int(stdin.ReadLine()) let depreciationRate = 100.00 / float estimatedLife let yearlyDepreciation = (machineCost - salvageValue) / float estimatedLife let bookValueYear0 = machineCost - (yearlyDepreciation * 0.00) let bookValueYear1 = machineCost - (yearlyDepreciation * 1.00) let bookValueYear2 = machineCost - (yearlyDepreciation * 2.00) let bookValueYear3 = machineCost - (yearlyDepreciation * 3.00) let bookValueYear4 = machineCost - (yearlyDepreciation * 4.00) let bookValueYear5 = machineCost - (yearlyDepreciation * 5.00) let bookValueYear6 = machineCost - (yearlyDepreciation * 6.00) let bookValueYear7 = machineCost - (yearlyDepreciation * 7.00) let bookValueYear8 = machineCost - (yearlyDepreciation * 8.00) let bookValueYear9 = machineCost - (yearlyDepreciation * 9.00) let bookValueYear10 = machineCost - (yearlyDepreciation * 10.00) let accumulatedDepreciation1 = yearlyDepreciation * 1.00 let accumulatedDepreciation2 = yearlyDepreciation * 2.00 let accumulatedDepreciation3 = yearlyDepreciation * 3.00 let accumulatedDepreciation4 = yearlyDepreciation * 4.00 let accumulatedDepreciation5 = yearlyDepreciation * 5.00 let accumulatedDepreciation6 = yearlyDepreciation * 6.00 let accumulatedDepreciation7 = yearlyDepreciation * 7.00 let accumulatedDepreciation8 = yearlyDepreciation * 8.00 let accumulatedDepreciation9 = yearlyDepreciation * 9.00 let accumulatedDepreciation10 = yearlyDepreciation * 10.00 printfn "===================================================================" printfn "Machine Depreciation Evaluation - Straight-Line Method" printfn "===================================================================" printfn $"Machine Cost: {machineCost:n}" printfn "-------------------------------------------------------------------" printfn $"Salvage Calue: {salvageValue:n}" printfn "-------------------------------------------------------------------" printfn $"Estimated Life: {estimatedLife:d} years" printfn "===================================================================" printfn "Depreciation Rate: %0.2f%c" depreciationRate '%' printfn "-------------------------------------------------------------------" printfn $"Yearly Depreciation: {yearlyDepreciation:n}/year" printfn "-------------------------------------------------------------------" printfn $"Monthly Depreciation: {(yearlyDepreciation / 12.00):n}/month" printfn "=====+=====================+============+==========================" printfn "Year | Yearly Depreciation | Book Value | Accumulated Depreciation" printfn "-----+---------------------+------------+--------------------------" let mutable year = 1; printfn " %i | |%10.2f |" year bookValueYear0 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear1 accumulatedDepreciation1 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear2 accumulatedDepreciation2 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear3 accumulatedDepreciation3 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear4 accumulatedDepreciation4 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear5 accumulatedDepreciation5 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear6 accumulatedDepreciation6 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear7 accumulatedDepreciation7 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear8 accumulatedDepreciation8 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear9 accumulatedDepreciation9 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear10 accumulatedDepreciation10 printfn "=====+=====================+============+=========================="
=================================================================== Machine Depreciation Evaluation - Straight-Line Method =================================================================== Enter the values to evaluation the depreciation of the machine Machine Cost: 8568.95 Salvage Value: 550 Estimated Life: 5 =================================================================== Machine Depreciation Evaluation - Straight-Line Method =================================================================== Machine Cost: 8,568.95 ------------------------------------------------------------------- Salvage Calue: 550.00 ------------------------------------------------------------------- Estimated Life: 5 years =================================================================== Depreciation Rate: 20.00% ------------------------------------------------------------------- Yearly Depreciation: 1,603.79/year ------------------------------------------------------------------- Monthly Depreciation: 133.65/month =====+=====================+============+========================== Year | Yearly Depreciation | Book Value | Accumulated Depreciation -----+---------------------+------------+-------------------------- 0 | | 8,568.95 | -----+---------------------+------------+-------------------------- 1 | 1,603.79 | 6,965.16 | 1,603.79 -----+---------------------+------------+-------------------------- 2 | 1,603.79 | 5,361.37 | 3,207.58 -----+---------------------+------------+-------------------------- 3 | 1,603.79 | 3,757.58 | 4,811.37 -----+---------------------+------------+-------------------------- 4 | 1,603.79 | 2,153.79 | 6,415.16 -----+---------------------+------------+-------------------------- 5 | 1,603.79 | 550.00 | 8,018.95 -----+---------------------+------------+-------------------------- 6 | 1,603.79 | -1,053.79 | 9,622.74 -----+---------------------+------------+-------------------------- 7 | 1,603.79 | -2,657.58 | 11,226.53 -----+---------------------+------------+-------------------------- 8 | 1,603.79 | -4,261.37 | 12,830.32 -----+---------------------+------------+-------------------------- 9 | 1,603.79 | -5,865.16 | 14,434.11 -----+---------------------+------------+-------------------------- 10 | 1,603.79 | -7,468.95 | 16,037.90 =====+=====================+============+========================== Press any key to close this window . . .
=================================================================== Machine Depreciation Evaluation - Straight-Line Method =================================================================== Enter the values to evaluation the depreciation of the machine Machine Cost: 15888.65 Salvage Value: 1250 Estimated Life: 10 =================================================================== Machine Depreciation Evaluation - Straight-Line Method =================================================================== Machine Cost: 15889 ------------------------------------------------------------------- Salvage Calue: 1250 ------------------------------------------------------------------- Estimated Life: 10 years =================================================================== Depreciation Rate: 10 % ------------------------------------------------------------------- Yearly Depreciation: 1464/year ------------------------------------------------------------------- Monthly Depreciation: 122/month =====+=====================+============+========================== Year | Yearly Depreciation | Book Value | Accumulated Depreciation -----+---------------------+------------+-------------------------- 0 | | 15888.65 | -----+---------------------+------------+-------------------------- 1 | 1463.87 | 14424.78 | 1463.87 -----+---------------------+------------+-------------------------- 2 | 1463.87 | 12960.92 | 2927.73 -----+---------------------+------------+-------------------------- 3 | 1463.87 | 11497.06 | 4391.60 -----+---------------------+------------+-------------------------- 4 | 1463.87 | 10033.19 | 5855.46 -----+---------------------+------------+-------------------------- 5 | 1463.87 | 8569.33 | 7319.32 -----+---------------------+------------+-------------------------- 6 | 1463.87 | 7105.46 | 8783.19 -----+---------------------+------------+-------------------------- 7 | 1463.87 | 5641.59 | 10247.06 -----+---------------------+------------+-------------------------- 8 | 1463.87 | 4177.73 | 11710.92 -----+---------------------+------------+-------------------------- 9 | 1463.87 | 2713.86 | 13174.78 -----+---------------------+------------+-------------------------- 10 | 1463.87 | 1250.00 | 14638.65 Press any key to close this window . . .
A Value Greater Than or Equal to Another: >=
The greater than or the equality operators can be combined to produce an operator as follows: >=. This is the "greater than or equal to" operator. The formula it follows is:
value1 >= value2
The comparison is performed on both operands: value1 and value2:
This operation can be illustrated as follows:
Here is an example that uses the >= operator:
let consumption = 0.74
let mutable pricePerCCF = 0.00
if consumption >= 0.50 then
pricePerCCF <- 35.00
let monthlyCharges = consumption * pricePerCCF
printfn "Gas Utility Company"
printfn "---------------------------------"
printfn $"Gas Consumption: {consumption}"
printfn $"Price Per CCF: {pricePerCCF}"
printfn $"Monthly Charges: {monthlyCharges}"
printfn "=================================="
This would produce:
Gas Utility Company --------------------------------- Gas Consumption: 0.74 Price Per CCF: 35.0 Monthly Charges: 25.9 ================================== Press any key to close this window . . .
Practical Learning: Comparing for a Value Greater Than or Equal to Another
printfn "===================================================================" printfn "Machine Depreciation Evaluation - Straight-Line Method" printfn "===================================================================" printfn "Enter the values to evaluation the depreciation of the machine" printf "Machine Cost: " let machineCost = float(stdin.ReadLine()) printf "Salvage Value: " let salvageValue = float(stdin.ReadLine()) printf "Estimated Life: " let estimatedLife = int(stdin.ReadLine()) let depreciationRate = 100.00 / float estimatedLife let yearlyDepreciation = (machineCost - salvageValue) / float estimatedLife let bookValueYear0 = machineCost - (yearlyDepreciation * 0.00) let bookValueYear1 = machineCost - (yearlyDepreciation * 1.00) let bookValueYear2 = machineCost - (yearlyDepreciation * 2.00) let bookValueYear3 = machineCost - (yearlyDepreciation * 3.00) let bookValueYear4 = machineCost - (yearlyDepreciation * 4.00) let bookValueYear5 = machineCost - (yearlyDepreciation * 5.00) let bookValueYear6 = machineCost - (yearlyDepreciation * 6.00) let bookValueYear7 = machineCost - (yearlyDepreciation * 7.00) let bookValueYear8 = machineCost - (yearlyDepreciation * 8.00) let bookValueYear9 = machineCost - (yearlyDepreciation * 9.00) let bookValueYear10 = machineCost - (yearlyDepreciation * 10.00) let accumulatedDepreciation1 = yearlyDepreciation * 1.00 let accumulatedDepreciation2 = yearlyDepreciation * 2.00 let accumulatedDepreciation3 = yearlyDepreciation * 3.00 let accumulatedDepreciation4 = yearlyDepreciation * 4.00 let accumulatedDepreciation5 = yearlyDepreciation * 5.00 let accumulatedDepreciation6 = yearlyDepreciation * 6.00 let accumulatedDepreciation7 = yearlyDepreciation * 7.00 let accumulatedDepreciation8 = yearlyDepreciation * 8.00 let accumulatedDepreciation9 = yearlyDepreciation * 9.00 let accumulatedDepreciation10 = yearlyDepreciation * 10.00 printfn "===================================================================" printfn "Machine Depreciation Evaluation - Straight-Line Method" printfn "===================================================================" printfn $"Machine Cost: {machineCost:n}" printfn "-------------------------------------------------------------------" printfn $"Salvage Calue: {salvageValue:n}" printfn "-------------------------------------------------------------------" printfn $"Estimated Life: {estimatedLife:d} years" printfn "===================================================================" printfn "Depreciation Rate: %0.2f%c" depreciationRate '%' printfn "-------------------------------------------------------------------" printfn $"Yearly Depreciation: {yearlyDepreciation:n}/year" printfn "-------------------------------------------------------------------" printfn $"Monthly Depreciation: {(yearlyDepreciation / 12.00):n}/month" printfn "=====+=====================+============+==========================" printfn "Year | Yearly Depreciation | Book Value | Accumulated Depreciation" printfn "-----+---------------------+------------+--------------------------" let mutable year = 1; printfn " %i | |%10.2f |" year bookValueYear0 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 if bookValueYear1 >= 0 then printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear1 accumulatedDepreciation1 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 if bookValueYear2 >= 0 then printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear2 accumulatedDepreciation2 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 if bookValueYear3 >= 0 then printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear3 accumulatedDepreciation3 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 if bookValueYear4 >= 0 then printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear4 accumulatedDepreciation4 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 if bookValueYear5 >= 0 then printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear5 accumulatedDepreciation5 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 if bookValueYear6 >= 0 then printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear6 accumulatedDepreciation6 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 if bookValueYear7 >= 0 then printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear7 accumulatedDepreciation7 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 if bookValueYear8 >= 0 then printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear8 accumulatedDepreciation8 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 if bookValueYear9 >= 0 then printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear9 accumulatedDepreciation9 printfn "-----+---------------------+------------+--------------------------" year <- year + 1 if bookValueYear10 >= 0 then printfn " %i | %0.2f |%10.2f | %10.2f" year yearlyDepreciation bookValueYear10 accumulatedDepreciation10 printfn "=====+=====================+============+=========================="
=================================================================== Machine Depreciation Evaluation - Straight-Line Method =================================================================== Enter the values to evaluation the depreciation of the machine Machine Cost: 8568.95 Salvage Value: 550 Estimated Life: 5 =================================================================== Machine Depreciation Evaluation - Straight-Line Method =================================================================== Machine Cost: 8,568.95 ------------------------------------------------------------------- Salvage Calue: 550.00 ------------------------------------------------------------------- Estimated Life: 5 years =================================================================== Depreciation Rate: 20.00% ------------------------------------------------------------------- Yearly Depreciation: 1,603.79/year ------------------------------------------------------------------- Monthly Depreciation: 133.65/month =====+=====================+============+========================== Year | Yearly Depreciation | Book Value | Accumulated Depreciation -----+---------------------+------------+-------------------------- 0 | | 8,568.95 | -----+---------------------+------------+-------------------------- 1 | 1,603.79 | 6,965.16 | 1,603.79 -----+---------------------+------------+-------------------------- 2 | 1,603.79 | 5,361.37 | 3,207.58 -----+---------------------+------------+-------------------------- 3 | 1,603.79 | 3,757.58 | 4,811.37 -----+---------------------+------------+-------------------------- 4 | 1,603.79 | 2,153.79 | 6,415.16 -----+---------------------+------------+-------------------------- 5 | 1,603.79 | 550.00 | 8,018.95 -----+---------------------+------------+-------------------------- Press any key to close this window . . .
=================================================================== Machine Depreciation Evaluation - Straight-Line Method =================================================================== Enter the values to evaluation the depreciation of the machine Machine Cost: 15888.65 Salvage Value: 1250 Estimated Life: 10 =================================================================== Machine Depreciation Evaluation - Straight-Line Method =================================================================== Machine Cost: 15,888.65 ------------------------------------------------------------------- Salvage Calue: 1,250.00 ------------------------------------------------------------------- Estimated Life: 10 years =================================================================== Depreciation Rate: 10.00% ------------------------------------------------------------------- Yearly Depreciation: 1,463.87/year ------------------------------------------------------------------- Monthly Depreciation: 121.99/month =====+=====================+============+========================== Year | Yearly Depreciation | Book Value | Accumulated Depreciation -----+---------------------+------------+-------------------------- 0 | | 15,888.65 | -----+---------------------+------------+-------------------------- 1 | 1,463.87 | 14,424.78 | 1,463.87 -----+---------------------+------------+-------------------------- 2 | 1,463.87 | 12,960.92 | 2,927.73 -----+---------------------+------------+-------------------------- 3 | 1,463.87 | 11,497.06 | 4,391.60 -----+---------------------+------------+-------------------------- 4 | 1,463.87 | 10,033.19 | 5,855.46 -----+---------------------+------------+-------------------------- 5 | 1,463.87 | 8,569.33 | 7,319.32 -----+---------------------+------------+-------------------------- 6 | 1,463.87 | 7,105.46 | 8,783.19 -----+---------------------+------------+-------------------------- 7 | 1,463.87 | 5,641.59 | 10,247.06 -----+---------------------+------------+-------------------------- 8 | 1,463.87 | 4,177.73 | 11,710.92 -----+---------------------+------------+-------------------------- 9 | 1,463.87 | 2,713.86 | 13,174.78 -----+---------------------+------------+-------------------------- 10 | 1,463.87 | 1,250.00 | 14,638.65 =====+=====================+============+========================== Press any key to close this window . . .
|
|||
Previous | Copyright © 2009-2023 FunctionX | Monday 14 February 2022 | Next |
|