class Add
def main
print 'Enter two numbers:'
x = Console.readLine
y = Console.readLine
print 'sum is', int.parse(x) + int.parse(y)
print 'done.'
that is the code i used when compiling in xamarin studio cobra language'
but i wonder why i get this error when compiling === Error: Argument 1 of method "parse" expects a non-nilable type (String), but the call is supplying a nilable type (String?). The declaration is "parse(s as String)", the call is supplying an arglist of type "(String?)". (printinput)
Forums
How to ADD inputs in a program
2 posts
• Page 1 of 1
Re: How to ADD inputs in a program
.readLine returns "String?" but .parse wants "String", in other words, nilable vs. non. You can change the code to:
... in other words nil coalesce with an empty string. This will guarantee non-nil.
x = Console.readLine ? ''
... in other words nil coalesce with an empty string. This will guarantee non-nil.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 31 guests