Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

exercise 12.01 Functions (Wallet)

import Foundation
import Glibc
 
func generateWallet(walletLenght: Int) -> [Int] {
    let typesOfBanknotes = [50, 100, 500, 1000, 5000]
    var wallet: [Int] = []
    for _ in 1...walletLenght {
        let randomIndex = 2
        wallet.append(typesOfBanknotes[randomIndex])
    }
    return wallet
}
func sumWallet(banknotsFunction wallet: (Int) -> ([Int]) ) -> Int? {
    let myWalletArray = wallet(5)
    var sum: Int = 0
    for oneBanknote in myWalletArray {
        sum += oneBanknote
    }
    return sum
}
print(sumWallet(banknotsFunction: generateWallet)!)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.