Page 1 of 1

c++ question about Sub procedures

Posted: Tue Nov 18, 2008 8:14 am
by Jim121
I the following code in my program but the compiler says that x, y and z are not declared. thanks in advance.

Code: Select all

 
int ang(float x,float y, float z, float angle_xz, float angle_yz, float distance){
    if(angle_xz<=90){
             y=distance*sin(angle_xz/60);
             z=distance*cos(angle_xz/60);
    }
    if(angle_xz>90 && angle_xz<=180){
             y=distance*sin((angle_xz-90)/60);
             z=distance*cos((angle_xz-90)/60);
    }
    if(angle_xz>180 && angle_xz<=270){
             y=distance*sin((angle_xz-180)/60);
             z=distance*cos((angle_xz-180)/60);
    }
    if(angle_xz>270){
             y=distance*sin((angle_xz-270)/60);
             z=distance*cos((angle_xz-270)/60);
    }
}

Code: Select all

ang(rect_basic_bronze_axe[i].x,rect_basic_bronze_axe[i].y,rect_basic_bronze_axe[i].z,rect_basic_bronze_axe[i].direction_xz,
             0,10);
        rect_basic_bronze_axe[i].x=rect_basic_bronze_axe[i].x+x;
        rect_basic_bronze_axe[i].y=rect_basic_bronze_axe[i].y+y;
        rect_basic_bronze_axe[i].z=rect_basic_bronze_axe[i].z+z;

Posted: Tue Nov 18, 2008 8:32 am
by aungsithu
rect_basic_bronze_axe.x=rect_basic_bronze_axe.x+x;
rect_basic_bronze_axe.y=rect_basic_bronze_axe.y+y;
rect_basic_bronze_axe.z=rect_basic_bronze_axe.z+z;


Where these underlined x,y,z came from?

Posted: Tue Nov 18, 2008 9:03 am
by JP
Yeah your compiler should have told you which line numbers give the errors and will probably pointed to the same ones as aungsithu pointed out. From your code snippet they certainly don't seem to be coming from anywhere sensible but it's hard to tell!

Posted: Tue Nov 18, 2008 10:36 am
by asparagusx
I also can't see how you are going to change the values in the ang function :

int ang(float x,float y, float z, float angle_xz, float angle_yz, float distance)

In the code you are changing x,y,z, but they are not declared correclty - you either have to define them as

float &x or
float *x (as an example)

if declared as float *

then use

*x = ........

Anton

Posted: Sat Nov 29, 2008 2:57 am
by Jim121
thanks
I should have seen it before the variables are not declared as global variables meaning that any where out of the sub they would be existent.