Let me guess, you're a mathematician, right?
does NOT set a to 2, and if b was, say, 5 before all this, a would be set to 5.
So you need to get values for a1,a2,b1,b2 BEFORE you do
because all the above two lines do is to set a and b to uninitialised data; the later reading in of values into a1 et al has no effect on vectors a and b.
You say this doesn't compile; could this be anything to do with the missing semicolon in sum()?