+ 1
How to take a input from the user in the coding language swift
I am making a code bit using swift. I am trying to take a input from the user and then caucalate the addition, subtraction, multiplication, division, and reamainder of the two input numbers the user gives. I tryed to use input() to take a input from the user but it wouldn't work. It only resulted in an error. (Affter the error I changed the numbers back into 1 and 1) I don't know how to take an input in swift. Can you please tell me how to do it? This is the link: https://www.sololearn.com/compiler-playground/crjsoPMwc1k3
7 Answers
+ 2
Liana Mercy Lee The maximum and minimum values of Int in Swift (defaulted to Int64 on 64-bit platforms such as Sololearn) are
9223372036854775807
-9223372036854775808
(Enough for handling a 9-digit multiplies another 9-digit.)
If you are running it on a 32-bit platform, it will be defaulted to Int32, and the limits are
2147483647
-2147483648
You can explicitly use Int32 or Int64 instead of Int to specify the variable type you prefer.
If you need to handle bigger numbers, you could consider Double if precision is not a big concern.
Otherwise, here is a link for your information:
https://stackoverflow.com/questions/25531914/biginteger-equivalent-in-swift
+ 5
Assuming the user will provide 2 Int inputs correctly. (For Sololearn, input them on separate lines when you run the program)
let a = Int(readLine()!)!
let b = Int(readLine()!)!
+ 3
https://www.sololearn.com/Discuss/2493372/?ref=app
Hope it's helpful to you
+ 2
Sakshi (Less Active), thanks but the page is not found for me... I don't know what went wrong but is is not found.
+ 2
Liana Mercy Lee update the sololearn app or clear cache in the storage section maybe then it's works and if not give the mail to sololearn with screenshot
info@sololearn.com
+ 1
Lochard,
Thanks! It worked for smaller integers but when I do bigger integers an error appears. This is my code in swift:
let a = Int(readLine()!)!
let b = Int(readLine()!)!
let addition = a+b
let subtraction = a-b
let multiplication = a*b
let division = a/b
let remainder = a%b
print("The value of the variable a is \(a).")
print("The value of the variable b is \(b).")
print("When you add the value of a and the value of b you get \(addition).")
print("When you subtract the value of b from the value of a you get \(subtraction).")
print("When you multiply the values of a and b together you get \(multiplication).")
print("When you divide the value of a by the value of b you get \(division).")
print("The remainder when you divide a by b is \(remainder).")
I'm not sure what I did that is wrong. I think that it is strange that it works for smaller numbers but doesn't work for larger numbers. This is the link so you can try the code yourself:
https://www.sololearn.com/compiler-playground/crjsoPMwc1k3
Thanks for the help!!!
-Liana
+ 1
Thanks Lochard!! I got it!!!