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...";
Question
neos
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