summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2022-12-15 11:27:32 -0700
committermo khan <mo@mokhan.ca>2022-12-15 11:27:32 -0700
commit742e5854f2bebc64e427fc53bc4c95b5df8b7207 (patch)
tree094b7c4f97d616866d89af8989938e97f42c56ef
parentba0d6a3b47b53b63e34c4a045c1f366399767394 (diff)
complete an exercise from chapter two
-rw-r--r--assignments/1.md14
1 files changed, 14 insertions, 0 deletions
diff --git a/assignments/1.md b/assignments/1.md
index 30559f3..5ecb711 100644
--- a/assignments/1.md
+++ b/assignments/1.md
@@ -23,6 +23,20 @@
heavily as a regular test.
4. Write an algorithm that gets the price for item A plus the quantity
purchased. The algorithm prints the total cost, including 6% sales tax.
+
+ ```ruby
+ def calculate_total(price, quantity, tax = 0.06)
+ return (price * quantity) * (1.0 + tax)
+ end
+ ```
+
+ ```plaintext
+ Get values for `price` and `quantity`
+ Set the value of `tax` to 1.06
+ Set the vlue of `total` to `price` multiplied by `quantity` multiplied by `tax`
+ Return the value of `total`
+ ```
+
5. Write an if/then/else primitive to do each of the following operations:
* a. Compute and display the value `x / y` if the value of `y` is not `0`. if
`y` does have the value `0`, then display the message `Unable to perform the