Page 1 of 1
cobra code for adding numbers please help
Posted:
Wed Jan 02, 2013 10:58 am
by basabz
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^^
Re: cobra code for adding numbers please help
Posted:
Wed Jan 02, 2013 3:28 pm
by Charles
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".
Re: cobra code for adding numbers please help
Posted:
Thu Jan 03, 2013 9:06 am
by basabz
thanks for the reply im just a freshmen into programming and i just want to learn more in other languages and thanks for advice
Re: cobra code for adding numbers please help
Posted:
Mon Jan 07, 2013 10:27 pm
by basabz
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
Re: cobra code for adding numbers please help
Posted:
Mon Jan 07, 2013 11:25 pm
by Charles
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.
Re: cobra code for adding numbers please help
Posted:
Tue Jan 08, 2013 6:48 am
by jessica
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
Re: cobra code for adding numbers please help
Posted:
Tue Jan 08, 2013 1:30 pm
by Charles
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.
Re: cobra code for adding numbers please help
Posted:
Tue Jan 08, 2013 7:10 pm
by jessica
thank you so much i really needed this for my assigned report on programming.
Re: cobra code for adding numbers please help
Posted:
Tue Jan 08, 2013 9:02 pm
by hopscc
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 ??