Fork and clone this repo. On your fork, answer and commit the follow questions. When you are finished, submit the link to your repo on Canvas.
Complete the function so that it will print out total cost after tax. Make sure to call the function afterwards.
let itemCost = 45.0
let nyTax = 0.08775
func totalWithTax() {
}
Then, modify the function you implemented to have a return type of Int
, and use an external name that looks more readable. Function calls should look something like "total cost of the item after tax"
Convert the the following if/else statement below into function with a String
return type.
let todaysTemperature = 72
if todaysTemperature <= 40 {
print("It's cold out.")
} else if todaysTemperature >= 85 {
print("It's really warm.")
} else {
print("Weather is moderate.")
}
Write a function named min2
that takes two Int
values, a
and b
, and returns the smallest one.
Function Definition
func min2(a: Int, b: Int) -> Int
Example:
Input: min2(a:1, b:2)
Output: 1
Write a function that takes an Int
and returns its last digit. Name the function lastDigit
. Use _ to ignore the external parameter name.
Function Definition:
func lastDigit(_ number: Int) -> Int
Example:
Input: lastDigit(12345)
Output: 5
Write a function that takes in any two positive integers and return the sum.
Write a function takes in any number grade and returns a corresponding letter grade.
Number Grade | Equivalent Letter Grade |
---|---|
100 | A+ |
90 - 99 | A |
80 - 89 | B |
70 - 79 | C |
65 - 69 | D |
Below 65 | F |
Make a calculator function that takes in three parameters (two numbers and one operator) and returns the answer of the operation.
Operator parameter: (+, -, x, /)
Write a function so that it will print out total cost after tip.
let mealCost = 45
let tipPercentage = 0.15
//Write your code below
let myFinalCost = totalWithTip() //Fill in the arguments
Write a function that will print out total cost after tip and tax.
let taxPercentage = 0.09
//Write your code below
let myFinalCostWithTipAndTax = totalWithTipAndTax() //Fill in the arguments in function
Implement a function named repeatPrint
that takes a string message
and a integer count
as parameters. The function should print message
count
number of times and then print a newline.
Example:
Input: repeatPrint(message: "+", count: 10)
Output: ++++++++++
Write a function named first
that takes an Int named n and returns an array with the first n numbers starting from 1.
Function Definition
func first(_ n: Int) -> [Int]
Example:
Input: first(3)
Output: [1, 2, 3]
Write a function that prints the numbers from 1 to x, except:
If the number if a multiple of 3, print "Fizz"
instead of the number
If the number is a multiple of 5, print "Buzz"
instead of the number
If the number is a multiple of 3 AND 5, print "FizzBuzz"
instead of the number
Your function should take in one parameter: x (the number to count up to)
Write a function named reverse
that takes an array of integers named numbers
as a parameter. The function should return an array with the numbers from numbers
in reverse order.
Example:
Input: reverse([1, 2, 3])
Output: [3, 2, 1]
Write a function that prints out the most frequently appearing Int in an array of Int.
Write a function that sums all the even indices of an array of Ints.
Write a function that flips a dictionary. All of the keys are now values and all of the values are now keys.
Example:
Input: [1: "hi", 5: "bye:]
Output: ["hi": 1, "bye": 5]
Write a function that finds the person with the second highest test score in a Dictionary that maps names to scores.
Example:
Input: ["Person 1": 83, "Person 2": 74, "Person 3": 82]
Output: "Person 3"
Write a function that determines if a value is inside of array.
Write a function takes an Int
as input, and returns true if it is even, or false if it is odd.
Using your new function, write code that prints out whether dieRoll
is even or odd:
let dieRoll = Int(arc4random_uniform(6) + 1)