Forums
cobra code for adding numbers please help
9 posts
• Page 1 of 1
cobra code for adding numbers please help
Hello im new to this language and i have searched many sites regarding on this, is there a way to add numbers using the cobra codes? if yes can someone give me an example thank you^^
- basabz
- Posts: 3
Re: cobra code for adding numbers please help
class X
def main
trace 3 + 5
print 3 + 5
trace .add(3, 5)
def add(a as int, b as int) as int
return a + b
Sounds like you're new to programming. If so, you are probably better off starting with the Python language and a book like "Python Programming for the Absolute Beginner".
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: cobra code for adding numbers please help
thanks for the reply im just a freshmen into programming and i just want to learn more in other languages and thanks for advice
- basabz
- Posts: 3
Re: cobra code for adding numbers please help
but is it possible to add in interactive way like the user is asked for the first number then for the second number then the result appears after entering the 2 numbers
- basabz
- Posts: 3
Re: cobra code for adding numbers please help
You can get input with Console.readLine and you can change it from a string to an int with either int.parse or int.tryParse. You can search for these on google to see examples in C# or VB, or to read their reference documentation.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: cobra code for adding numbers please help
i have read the last posts and i have a problem about the Console.readline, i've also checked the reference of C# and VB
and it just gave me confusion because they have different syntax and it gave me errors. can you share me a cobra code about adding numbers with the use of Console.readline, int.Parse etc. so that it will ask the user on what numbers he/she wants to add? thank you so much
and it just gave me confusion because they have different syntax and it gave me errors. can you share me a cobra code about adding numbers with the use of Console.readline, int.Parse etc. so that it will ask the user on what numbers he/she wants to add? thank you so much
- jessica
- Posts: 3
Re: cobra code for adding numbers please help
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.'
- Code: Select all
Enter two numbers:
3
4
sum is 7
done.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: cobra code for adding numbers please help
thank you so much i really needed this for my assigned report on programming.
- jessica
- Posts: 3
Re: cobra code for adding numbers please help
Other than giving you the code to do what you want
what would you have needed/wanted to see (in compiler, doc, website,..)
to make it easy/easier for you to work out what you needed to do yourself ??
what would you have needed/wanted to see (in compiler, doc, website,..)
to make it easy/easier for you to work out what you needed to do yourself ??
- hopscc
- Posts: 632
- Location: New Plymouth, Taranaki, New Zealand
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 21 guests