#!/usr/bin/env swift; /****************************************************************************** * This program demonstrates how to prompt the user for input. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ import Foundation import Utils // Begin Main do { var favoriteInt:Int var favoriteLong:Int64 var favoriteDouble:Double var favoriteIntInput:String favoriteIntInput = Utils.prompt("What is your favorite small integer? ") try favoriteInt = Utils.stoi(favoriteIntInput) var favoriteLongInput:String favoriteLongInput = Utils.prompt("What is your favorite large integer? ") try favoriteLong = Utils.stol(favoriteLongInput) var favoriteDoubleInput:String favoriteDoubleInput = Utils.prompt("What is your favorite floating point? ") try favoriteDouble = Utils.stod(favoriteDoubleInput) let sum:Double = Double(favoriteInt) + Double(favoriteLong) + favoriteDouble print(Utils.format("All together they add up to {0:f}!", sum)) } catch let ex as NumberFormatError { print("Bad input! " + ex.localizedDescription) } catch { print("Don't know what went wrong!") } exit(EXIT_SUCCESS)