
-----------------------------------
MysticVegeta
Sat Feb 19, 2005 10:10 pm

Adding within :?:
-----------------------------------
i know the topic doesnt explain a lot but i will try my best to describe the problem, um, supposedly, i have

var amount : int
get amount

var numbers : array 1..amount of int

for s : 1..amount
get numbers(s)
end for



Now lets say i chose 5 as the amount and i enter following values ->
1, 2, 3, 4, 5

Now, supose there is an answer variable which is 9. How do i get it to calculate all the possible additions that are:

1 + 2 + 3 + 4 + 5 = 15
1 + 2 = 3
1 = 1
1 + 2 + 3 = 6
1 + 2 + 3 + 4 = 10

2 + 3 + 4 + 5 = 14
2 + 3 + 4 = 9
2 + 3 = 5
2 = 2

So on and so forth with 3, 4 and 5. After doing that i want it to pick the equal or closest value to "answer" and state that addition sum. Is there a way to do it? 
 :?:  :?:

-----------------------------------
ssr
Sun Feb 20, 2005 8:37 am


-----------------------------------
do a for loop
and change the array number each time 
 8) [/code]

-----------------------------------
MysticVegeta
Sun Feb 20, 2005 11:31 am


-----------------------------------
ok i knew that but how do i do it if i dont know the amount of numbers the user  has input :S

-----------------------------------
Bacchus
Sun Feb 20, 2005 8:02 pm


-----------------------------------
yes you do, you have the user input the amount in the very first part of the program.. its even under the variable amount.. personally in would use nested for loops

-----------------------------------
StarGateSG-1
Mon Feb 21, 2005 12:26 pm

Arrays Suck
-----------------------------------
arrays are not a good thing , you need to use a vector with turing doesn't support or i have never found one. you just have to ask the user for input for now.

-----------------------------------
AsianSensation
Mon Feb 21, 2005 4:28 pm


-----------------------------------
true, Turing doesn't have vectors, but you can use the flexible arrays, which are just dynamic arrays. 

There is a tutorial floating around in the tutorial section. Check it out, it will probably solve what you need to do.

-----------------------------------
zylum
Mon Feb 21, 2005 4:55 pm


-----------------------------------
i dont think his problem is with arrays, i think he wants to find the combination of numbers that will add up as closely as possible to the given number. in this case i would go for recursion if the amount of numbers is small... or you could do this: 

%get numbers
var nums : flexible array 1 .. 0 of int
var s : int

put "enter numbers. end with int 