Sunday, August 2, 2009

Help getting my code C++ code to replace a value.?

What i want is, each time I run my void rotate(...) function, i want the function to do the calculations and replace the coordinates of the point. I subplemented the constants 6,6 for dx,dy and it appears that the function isnt replacing the values at all. How do i get the program to replace my co-ordinates?





{


double new_x = (((p.get_x()*cos(angle))+(p.get_y()*sin(...


double new_y = (((-(p.get_x())*sin(angle))+(p.get_y()*c...


double dx = p.get_x()- new_x;


double dy = p.get_y()- new_y;


p.move(dx,dy);


}


...


int main()


{





cout%26lt;%26lt; "The original point p (5,5) rotated 5 times by 10 degrees then scaled 5 times by .95 is:""\n";


Point p(5,5);


double angle = 10;


double scale = .95;


int rotation_count = 0;


int scale_count = 0;





while (rotation_count%26lt;5)


{


rotate( p, angle);


cout%26lt;%26lt; "The point is now " %26lt;%26lt; p.get_x() %26lt;%26lt; "," %26lt;%26lt; p.get_x()%26lt;%26lt; "\n";


rotation_count++;


}


return 0;


}

Help getting my code C++ code to replace a value.?
The Yahoo editor chopped off a lot of your code. Break up the lines so it doesn't truncate them to "...".





Since it is impossible to tell, are you sure you are passing your variables by reference rather than value?





---EDIT---





Saw this on one of your other submissions:





void rotate(Point p, double angle)





It should be





void rotate(Point%26amp; p, double angle)








---EDIT 2---





You changed the line? Your original code had





cout%26lt;%26lt; "The point is now " %26lt;%26lt; p.get_x() %26lt;%26lt; "," %26lt;%26lt; p.get_x()%26lt;%26lt; "\n";





which should be ok. But it looks as if your error message is complaining about line 50 :





cout%26lt;%26lt; "The point is now " %26lt;%26lt; p.get_x %26lt;%26lt; "," %26lt;%26lt; p.get_x %26lt;%26lt; "\n";





Make it p.get_x() and p.get_y(). The lack of parens for the function call is probably causing your error. It almost looks as if you are confusing c++ and C#. Something like p.get_x would be a property in C#.
Reply:You deserve better than a "C++" for all that work, looks more like an A++ to me...


You do have crappy sentance structure however!?!?!?


No comments:

Post a Comment