• 0

whats up with this?


Question

hey,

I wrote this program to find the midpoint of a line segment, but Im getting these numbers back as the midpoint

(2147348480, 4313352), or the program just closes because it causes an error when I switch all the int's to float's because Im not sure which to use, int or float. I want it to be able to handle negative numbers, and decimals. Im a newbie!

heres the code

/*

midpofloat.cpp - calculates the midpofloat of a line segment.

*/

#include

float calX(float x1, float x2) {

float Mx1 = x1 - x2;

float Mx = Mx1 / 2;

return Mx;

}

float calY(float y1, float y2) {

float My1 = y1 - y2;

float My = My1 / 2;

return My;

}

int main() {

float x1, x2;

float y1, y2;

cout << "Please enter the first X co-ordinate...";

cin >> x1;

cout << "Please enter the second X co-ordinate...";

cin >> x2;

cout << "Please enter the first Y co-ordinate...";

cin >> y1;

cout << "Please enter the second Y co-ordinate...";

cin >> y2;

calX(x1, x2);

calY(y1, y2);

float Mx, My;

cout << Mx << ", " << My << "n";

return 0;

}

any suggestions? what am i doing wrong?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Well first change

&lt;pre&gt;calX(x1, x2); 

calY(y1, y2); 



float Mx, My;&lt;/pre&gt;

into

&lt;pre&gt;float Mx, My; 



Mx = calX(x1, x2); 

My = calY(y1, y2);&lt;/pre&gt;

Think that'll work

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.