Midpoint - Slope formula

Published on: August 10, 2010

This is just another video of my Easy Programming series where I show you a tutorial to find the midpoint and slope of a line after the user enters two points of the line. The program also breaks down Cout, Cin, as well as use seven variables. You can also customize the program to your liking. The program used is Visual Studio 2008 C++ and this is a great way to learn both math and programming.

If you want a copy of the program codes, let me know and I'll send them your way.

Remember to checkout the Codesnip below to review the C++ code yourself! Feel free to copy the code, but I ask that you please provide credit if you leave the code unchanged when you use it.


//Programmer: Nazmus
//Program:  Midpoint-Slope
//Purpose:  Get Midpoint and the Slope of a line
//Website:  EasyProgramming.net

#include <iostream>
using namespace std;

void main()
 float x1, x2, y1, y2, midpoint1, midpoint2, slope;

 cout << "This program will help you calculate the Midpoint & Slope of a line." << endl<<endl;

 cout << "Please input the value of the first point, x1 & y1 with a space in between: ";
 cin >> x1 >> y1;

 cout << "Thank you, please input the value of the second point: ";
 cin >> x2 >> y2;

 midpoint1 = (x1 + x2) / 2;
 midpoint2 = (y1 + y2) / 2;

 slope = (y2 - y1) / (x2 - x1);

 cout <<endl<<  "The slope of the line is " << slope << '.' << endl << endl;
 cout  <<  "The midpoint of the line is (" << midpoint1 << ", " << midpoint2 << ")." << endl <<endl;
 cout << "Thanks for using this program." << endl;