This is my code that I wrote for my class but it doesn't seem to work as intended. It compiles fine and works fine just up to the point where try to get it to solve a regular slope value that is neither horizontal nor vertical. Any help would be much appreciated!
Hi, much appreciated quick reply! I'm not 100% sure what you mean by this. Would you like me to tidy it up for you and re post or is the formatting the problem with my code? If it's the latter I would really appreciate it if you would explain.
The formula for calculating the slope is given in line 33 and for the distance between plot points in line 29. The program works fine for the distance between the plot points so we can disregard that. However, for the slope it works and spits out the proper statements if the answer is horizontal or vertical. The only thing wrong is if I try to get it to calculate the slope that is not one of these special cases, it spits out slope = inf and the line is vertical which doesn't make sense. Thanks for your patience!
slope is equal to= ((y1-y2)/(x1-x2)); y1,y2,x1,x2 being points on a given graph.
The distance between points is = sqrt(pow((x2-x1) ,2) + pow((y2 - y1) ,2)) where x and y are both points on a graph as well.
Once they are calculated, the program spits out the values. I want it to say if the slope is undefined (divided by zero) that the line is vertical. Likewise if the slope is 0, I want it to say that the line is horizontal.
The issue that I'm having is that it it saying the line is vertical when the slope has been calculated to be not undefined.