Variable scoping problem here,
Why make x,y & z a global variable when you only need it within the function. You might as well do this in C not C++.