A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

[C++]Some math calculator I used in Highschool.

1.1k views · started by defkult ·
#1
[C++]Some math calculator I used in Highschool.


#include <math.h>
#include <iostream>

using namespace std;

int main()
{
int x1,x2,y1,y2,answer,answerx,answery;
double distance;
char choice;

cout << "Menu:\nm = Midpoint\nd = Distance\ns=Slope\np=Slope Point\n";
cin >> choice;
while(choice != 'x')
{

if(choice == 'm')
{
cout << "Enter the X1 coordinate: ";
cin >> x1;
cout << "Enter the Y1 coordinate: ";
cin >> y1;
cout << "Enter the X2 coordinate: ";
cin >> x2;
cout << "Enter the Y2 coordinate: ";
cin >> y2;
answerx = (((x1) + (x2))/2);
answery = (((y1) + (y2))/2);
printf("The Midpoint is : (%i,%i)\n",answerx,answery);
}
if(choice == 'd')
{
cout << "Enter the X1 coordinate: ";
cin >> x1;
cout << "Enter the Y1 coordinate: ";
cin >> y1;
cout << "Enter the X2 coordinate: ";
cin >> x2;
cout << "Enter the Y2 coordinate: ";
cin >> y2;

distance = sqrt(pow(x2-x1,2) + pow(y2-y1,2));
printf("The Distance is: %i\n",distance);
}
if(choice == 's')
{
cout << "Enter The X1 Coordinate: ";
cin >> x1;
cout << "Enter The Y1 Coordinate: ";
cin >> y1;
cout << "Enter The X2 Coordinate: ";
cin >> x2;
cout << "Enter The Y2 Coordinate: ";
cin >> y2;
printf("M = %i - %i / %i - %i\n",y2,y1,x2,x1);
}
if(choice == 'p')
{
cout << "Enter The Y Coordinate: ";
cin >> y1;
cout << "Enter The X Coordinate: ";
cin >> x1;
printf("y - %i = m(x - %i)\n",y1,x1);
}
system("Pause");
break;
}
}

#2
Just in case someone tries to compile this in a non-Windows environment: system("Pause") only works on Windows.
#3
Oh. I forgot about that. Thanks for the tip off. :)