/* Interest.swift (c) Kari Laitinen http://www.naturalprogramming.com 2021-09-14 File created. This program demonstrates an initialized two-dimensional array. */ import Foundation let compound_interest_table = [ [ 5.00, 10.25, 15.76, 21.55, 27.63, 34.01, 40.71, 47.75 ], [ 6.00, 12.36, 19.10, 26.25, 33.82, 41.85, 50.36, 59.38 ], [ 7.00, 14.49, 22.50, 31.08, 40.26, 50.07, 60.58, 71.82 ] ] print( "\n This program calculates the compound interest" + "\n for a given sum of money (principal). \n" + "\n Give the loan amount: ", terminator: "" ) let given_sum_of_money = Double( readLine()! )! print( "\n Give the interest percentage ( 5, 6, or 7): ", terminator: "" ) let interest_percentage = Int( readLine()! )! print( "\n Give the loan period in years ( max. 8 ): ", terminator: "" ) let loan_period_in_years = Int( readLine()! )! let compound_interest = ( given_sum_of_money / 100.0 ) * compound_interest_table[ interest_percentage - 5 ] [ loan_period_in_years - 1 ] //print( "\n Compound interest is: \( compound_interest ) \n\n" ) print( String( format: "\n For a loan of %.2f you must pay" + "\n %.2f as compound interest after %d years. \n\n", given_sum_of_money, compound_interest, loan_period_in_years ) )