Code:
#include <iostream>
#include <cmath>
using namespace std;
int main (double x1 , double y1 , double x2 , double y2)
{
double midpointx;
double midpointy;
cout << "First Coordinate.\n" << endl << "Enter x " << endl;
cin >> x1;
cout << "Enter y " << endl;
cin >> y1;
cout << "Second Coordinate.\n" << endl << "Enter x " << endl;
cin >> x2;
cout << "Enter y " << endl;
cin >> y2;
midpointx = (x1 + x2)/2;
midpointy = (y1 + y2)/2;
cout << "The midpoint of your two coordinates is: ( " << (midpointx) << " , " << (midpointy) << " ). " << endl;
cin.get();
return 0;
}
i made this basic program and i tested it and it works but i have a problem. If the answer is in a decimal such as doing the equation (5 divided by 2). The answer will come out as 2.5. Is there a way i can make the answer in a fration such as 5 over 2?. Also preferably the answer should be in fraction form if the equation does not divide evenly and should be a whole number if it does divide evenly.
EX : (5 divided by 2 answer should be 5/2)
(6 divided by 2 answer should be 3 and not 3/1)
Thanks!