← Back
Code Challenge 1.8 - Line Slope Calculator
Introduction
When graphing lines in Algebra, it’s important to understand how to calculate the slope of a line. To calculate the slope, at least two points must be identified. You can then calculate the slope using the Slope Formula. The Slope Formula is defined as:
where m is the slope, the ordered pair (x1, y1) is the first point, and the ordered pair (x2, y2) is the second point.
Skills to Practice
- Prompting a user for input
- Saving user input to variables
- Converting input to the correct data type (if necessary)
- Performing arithmetic calculations
- Formatting custom output using variables
Challenge Tasks
- Create a console project named Challenge 1-8.
- Prompt the user to enter four values corresponding to two points of a line i.e. (x1, y1) and (x2, y2).
- Calculate the slope using the Slope Formula.
- Optionally, round the answer to three decimal places.
- Display the calculated slope to the user in a clear and formatted manner.
Sample Output
Enter x1: 2 [Enter]
Enter y1: 3 [Enter]
Enter x2: 12 [Enter]
Enter y2: 14 [Enter]
The slope of the line is 1.1