Computer Science Canada Adding within :?: |
Author: | MysticVegeta [ Sat Feb 19, 2005 10:10 pm ] | ||
Post subject: | Adding within :?: | ||
i know the topic doesnt explain a lot but i will try my best to describe the problem, um, supposedly, i have
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? ![]() ![]() |
Author: | ssr [ Sun Feb 20, 2005 8:37 am ] | ||
Post subject: | |||
do a
and change the array number each time 8) [/code] |
Author: | MysticVegeta [ Sun Feb 20, 2005 11:31 am ] |
Post subject: | |
ok i knew that but how do i do it if i dont know the amount of numbers the user has input :S |
Author: | Bacchus [ Sun Feb 20, 2005 8:02 pm ] |
Post subject: | |
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 |
Author: | StarGateSG-1 [ Mon Feb 21, 2005 12:26 pm ] |
Post subject: | 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. |
Author: | AsianSensation [ Mon Feb 21, 2005 4:28 pm ] |
Post subject: | |
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. |
Author: | zylum [ Mon Feb 21, 2005 4:55 pm ] | ||
Post subject: | |||
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:
using binary ![]() |
Author: | MysticVegeta [ Fri Feb 25, 2005 9:02 pm ] |
Post subject: | |
mind explaining an overview of the code?? thanks! |