Advertisement
hassanbanat

switch

Jan 8th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.33 KB | None | 0 0
  1. //
  2. //  main.swift
  3. //  new2
  4. //
  5. //  Created by ios on 1/8/19.
  6. //  Copyright © 2019 ios. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10.  
  11. //print ("enter a number: ")
  12. //var number:String? = readLine()!
  13. //
  14. //for number in 0...Int(number!)!{
  15. //
  16. //    print(number)
  17. //}
  18. //
  19. //print ("enter a number1: ")
  20. //
  21. //var n1:String? = readLine()!
  22. //print ("enter a number2: ")
  23. //var n2:String? = readLine()!
  24. //
  25. //let x = Int (n1!)!
  26. //let z = Int (n2!)!
  27. //for n1 in (x...z) {
  28. //
  29. //    print(n1)
  30. //}
  31.  
  32.  
  33. //for i in 0...8 {
  34. //
  35. //    for _ in 0...i {
  36. //        print ("*", terminator: "")
  37. //    }
  38. //print("")
  39. //}
  40.  
  41. print ("enter a number1: ")
  42. var price:String? = readLine()!
  43. let x = Double (price!)!
  44. print("price before discount: \(price!)")
  45.  
  46. switch x {
  47.    
  48. case ...600:
  49.    
  50.     let y:Double = (Double (x) * 0.02)
  51.     print ("price after discount \(x - y)")
  52. case 600...999:
  53.     let y:Double =  (Double (x) * 0.04)
  54.      print ("price after discount \(x - y)")
  55. case 1000...1449:
  56.     let y:Double =  (Double (x) * 0.08)
  57.      print ("price after discount \(x - y)")
  58. case 1500...1999:
  59.     let y:Double =  (Double (x) * 0.12)
  60.      print ("price after discount \(x - y)")
  61. case 2000...:
  62.     let y:Double =  (Double (x) * 0.15)
  63.      print ("price after discount \(x - y)")
  64.    
  65.    
  66.    
  67. default:
  68.     print ("enter PRICE")
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement