Ok, I need some help...(UPDATED)

Kinja'd!!! "Cherry_man1" (Cherry_man1)
11/18/2013 at 11:30 • Filed to: None

Kinja'd!!!1 Kinja'd!!! 25

I know some people here are computer programmers. And I need some Help with this program.

I'll take a screen shot of what I'm dealing with.

Kinja'd!!!

I am trying to add up the index values like to get it to add up like with a value of 10 to go something like 1+2+3+4+5+6+7+8+9+10 = 55

I know this is something SUPER simple but its evading me.....help?

Here is a wagon and the ad to get it for taking the time with this:

Kinja'd!!!

!!!error: Indecipherable SUB-paragraph formatting!!!

UPDATE: (Read instructions...needed the try.parse)

Kinja'd!!!

DISCUSSION (25)


Kinja'd!!! ddavidn > Cherry_man1
11/18/2013 at 11:37

Kinja'd!!!0

Maybe I'm not quite clear on what you want to do, but this looks all right to me. Maybe you can post the output vs. desired output?

I guess I'm not clear on the 10. Do you want the values to add up to inttotal - 10?


Kinja'd!!! Cherry_man1 > ddavidn
11/18/2013 at 11:41

Kinja'd!!!0

Im trying to go from an index of 1 to add up the index values like index 1 = 1 etc. like adding up all the numbers from 1 to 10 together to get the answer


Kinja'd!!! CalzoneGolem > Cherry_man1
11/18/2013 at 11:41

Kinja'd!!!2

I think you need another variable and do

intanswer = intanswer + intindex

intindex++

then when you're out of the loop intanswer will contain the answer.


Kinja'd!!! ddavidn > Cherry_man1
11/18/2013 at 11:43

Kinja'd!!!0

Do what CalzoneGolem recommended. Unless you're using old VB, then intindex++ won't work and you'll need to use intindex = intindex + 1


Kinja'd!!! The Jevans > CalzoneGolem
11/18/2013 at 11:45

Kinja'd!!!0

exactly, otherwise you would end up with inttotal as the answer every time.


Kinja'd!!! Cherry_man1 > The Jevans
11/18/2013 at 11:47

Kinja'd!!!0

ok i'm getting close I got a value of 12 to come back but thats not quite right....


Kinja'd!!! dlp000 > Cherry_man1
11/18/2013 at 11:48

Kinja'd!!!1

Your calculations is adding 1 to the current varriable, that means 1 becomes 2 then 3 then 4. IE 1 +1, then 2+1, then 3+1 and so on. what you describe as 1+2+3... would require var1 = var1 + 1, var2 = var2 + var1, if both start as 0 then your results would be

var1 = 1 var 2 = 1

var1 = 2 var 2 = 3

var 1 = 3 var 2 = 6

and so on.

D


Kinja'd!!! The Jevans > Cherry_man1
11/18/2013 at 11:50

Kinja'd!!!0

Can you post the revised code?


Kinja'd!!! Cherry_man1 > The Jevans
11/18/2013 at 11:52

Kinja'd!!!0

Kinja'd!!!


Kinja'd!!! Cherry_man1 > The Jevans
11/18/2013 at 11:59

Kinja'd!!!0

Ok here is another revised code

Kinja'd!!!


Kinja'd!!! CalzoneGolem > Cherry_man1
11/18/2013 at 12:00

Kinja'd!!!0

Oh yeah you'll want < inttotal + 1


Kinja'd!!! The Jevans > Cherry_man1
11/18/2013 at 12:02

Kinja'd!!!0

inttotal = intindex + intvalue

should be

inttotal = inttotal + intindex


Kinja'd!!! davedave1111 > Cherry_man1
11/18/2013 at 12:03

Kinja'd!!!1

You need to actually do something inside the loop, like add that iteration's index number to some variable or other. But it's an odd way to do it. Do you have a requirement to use a loop for some kind of teaching exercise?

I'd use Gauss's method instead:

Another famous story has it that in primary school after the young Gauss misbehaved, his teacher, J.G. Büttner, gave him a task : add a list of integers in arithmetic progression ; as the story is most often told, these were the numbers from 1 to 100. The young Gauss reputedly produced the correct answer within seconds, to the astonishment of his teacher and his assistant Martin Bartels .

Gauss's presumed method was to realize that pairwise addition of terms from opposite ends of the list yielded identical intermediate sums: 1 + 100 = 101, 2 + 99 = 101, 3 + 98 = 101, and so on, for a total sum of 50 × 101 = 5050.

http://en.wikipedia.org/wiki/Carl_Frie…

That generalises to

Kinja'd!!!

.


Kinja'd!!! The Jevans > Cherry_man1
11/18/2013 at 12:03

Kinja'd!!!0

you probably also should define inttotal as 0 when you initialize it.


Kinja'd!!! Cherry_man1 > The Jevans
11/18/2013 at 12:06

Kinja'd!!!0

Still 19 as an output


Kinja'd!!! Meatcoma > Cherry_man1
11/18/2013 at 12:06

Kinja'd!!!0

If you move your messagebox into your loop you can see what it displays each time. Unless of course you are debugging it, then you can just put a breakpoint on the do while loop and check the values each pass. Your logic is correct but sometimes the code behaves erratically and you have to do what CalzoneGolem stated and pass the variable to a completely new one.


Kinja'd!!! MontegoMan562 is a Capri RS Owner > Cherry_man1
11/18/2013 at 12:08

Kinja'd!!!0

Badass torino wagon! It's like my car but ford wagon (and a bit newer).

he's right 100% that it's the only one at the car show!

As for the code, the other guys are doing better than I would so I'll leave it to them. Like they've said it doesn't look like you are too far off.


Kinja'd!!! Meatcoma > Cherry_man1
11/18/2013 at 12:10

Kinja'd!!!0

If I input 2 into your inputbox what should the calculation equal?


Kinja'd!!! Cherry_man1 > Meatcoma
11/18/2013 at 12:12

Kinja'd!!!0

Default value is 10 so the output should be 55 if it worked right


Kinja'd!!! The Jevans > Cherry_man1
11/18/2013 at 12:16

Kinja'd!!!0

intindex = 1

intvalue = 0

inttotal = 0

intvalue = input

do while intindex < (intvalue + 1)

inttotal = inttotal + intindex

intindex ++

loop

return inttotal


Kinja'd!!! Cherry_man1 > The Jevans
11/18/2013 at 12:23

Kinja'd!!!0

ok got 100 from that


Kinja'd!!! Cherry_man1 > The Jevans
11/18/2013 at 12:25

Kinja'd!!!0

Kinja'd!!!

Code updated


Kinja'd!!! Meatcoma > Meatcoma
11/18/2013 at 12:31

Kinja'd!!!0

Try this, then add your inputbox in.

dim total as Integer = 0

dim index as Integer =0

dim default as Integer = 10

Do while index <= default

total = total + index

index += 1

Loop


Kinja'd!!! The Jevans > Cherry_man1
11/18/2013 at 12:32

Kinja'd!!!0

inttotal = inttotal + intindex

make sure that line is right


Kinja'd!!! Cherry_man1 > The Jevans
11/18/2013 at 12:42

Kinja'd!!!1

Thats it! that did it! YOU ARE MY HERO! Mystichrome

Kinja'd!!!