Computer Science Canada

number adding

Author:  Hackster [ Sat Mar 06, 2004 2:39 pm ]
Post subject:  number adding

hello , im new, i need help with a program i have to do, no one can help me at school. ok, i need to make three three digit numbers and add the three numbers of each number to the numbers of the other numbers.

Mod Edit: Post in the right section next time. Moved.

Author:  Hackster [ Sat Mar 06, 2004 2:50 pm ]
Post subject: 

i just thought i would get more replies and faster help, sorry!

Author:  zylum [ Sat Mar 06, 2004 2:53 pm ]
Post subject: 

can you be a little bit more descriptive?

you mean add all the digits in each number and the add all the sums of the digits?

Author:  Mazer [ Sat Mar 06, 2004 2:56 pm ]
Post subject: 

That doesn't make alot of sense, but here's what I got from it: you need to add the digits from each number to the digits of the other numbers? Do you mean like
number 1: digits a,b,c
number 2: digits d,e,f
number 3: digits g,h,i
number 4: digits a+d+g,b+e+h,c+f+i

Like that?
It'd also help if you posted the code you have so far, so as to clarify your problem.

Author:  Hackster [ Sat Mar 06, 2004 2:58 pm ]
Post subject: 

that i what i need , but i didn't start it yet, i thought i would get some ideas on how to do it , then starrt the code part, cuz im not too good with turing right now

Author:  zylum [ Sat Mar 06, 2004 3:00 pm ]
Post subject: 

does it matter if each new digit is greater than 9?

Author:  Mazer [ Sat Mar 06, 2004 3:03 pm ]
Post subject: 

I try not to write entire programs for people, because when I do I tend to get sarcastic and angry and make mini virus-like programs. Ah...

Anyways, as I said, use intstr and strint.
Suppose you have your numbers
code:

var number1, number2, number3 : int

And let's assume that you've already set them all to some 3 digit numbers. You can convert the number to a string and look at each 'character' of the string individually.
For example, if you have an integer, 654, you can convert it to a string and get "654", or to look at the first digit, "6". In code, it would be something like put intstr(number1)(1).

Author:  Hackster [ Sat Mar 06, 2004 3:08 pm ]
Post subject: 

ok i think i understand , ill post the code for you to check over later, just so i don't screw it up too bad

Author:  zylum [ Sat Mar 06, 2004 3:16 pm ]
Post subject: 

so the first digit of the new number will be something like:

code:

d1 := strint (intstr (n1) (1)) + strint (intstr (n2) (1)) + strint (intstr (n3) (1))


-zylum

Author:  apomb [ Sat Mar 06, 2004 3:45 pm ]
Post subject: 

I had a similar program, here's some of the code, the basis of the strint intstr thing
code:
-----------------------------Main Program----------------------*/
%------------------------------variables------------------------
var num4, num3, one1, one2, two1, two2, three1, three2 : string
var num1, num2, num5, num6, total, a, b, c : int
%---------------------------------------------------------------
put "Enter two three digit numbers"
get num1
get num2
cls
%------------------Converting from sting to integer-----------
num4 := intstr (num1)
num3 := intstr (num2)
one1 := num4 (1)
one2 := num3 (3)
num5 := strint (one1)
num6 := strint (one2)
a := (num5 + num6)
num4 := intstr (num1)
num3 := intstr (num2)
two1 := num4 (2)
two2 := num3 (2)
num5 := strint (two1)
num6 := strint (two2)
b := (num5 + num6)
num4 := intstr (num1)
num3 := intstr (num2)
three1 := num4 (3)
three2 := num3 (1)
num5 := strint (three1)
num6 := strint (three2)
c := (num5 + num6)


just remember to change the variables.

Author:  zylum [ Sat Mar 06, 2004 4:08 pm ]
Post subject: 

or you could do this:

code:
var n1, n2, n3, n4, d1, d2, d3 : int
put "enter the 3 numbers"
get n1, n2, n3

d1 := strint (intstr (n1) (1)) + strint (intstr (n2) (1)) + strint (intstr (n3) (1))
d2 := strint (intstr (n1) (2)) + strint (intstr (n2) (2)) + strint (intstr (n3) (2))
d3 := strint (intstr (n1) (3)) + strint (intstr (n2) (3)) + strint (intstr (n3) (3))

n4 := strint (intstr (d1) + intstr (d2) + intstr (d3))

put n4


-zylum


: