I am having trouble calling a slope function in my code.

Why isn't my code working and how can i make it work? i am supposed to call the slope function while the user inputs x1,y1,x2,y2 and it outputs the slope. I am new at coding, so please be in depth with your answer. thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double findSlope(double, double, double, double);	//function prototype

int main()


{
	double x1,y1,x2,y2,slope;
	

	cout<<"Please input the values for x1, y1, x2, and y2"<<endl;
	cin>> x1, y1, x2, y2;

	slope = findSlope(x1, y1, x2, y2);	// call the function

	cout<<"The slope between the two given points is "<<slope<<endl;

	return 0;
}

double findSlope(double x1 ,double y1 ,double x2 ,double y2 )

{	
	double slope;


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

	
	system ("pause");
	return slope;
}

cin>> x1, y1, x2, y2; should be cin >> x1 >> y1 >> x2 >> y2;
wow, thanks! such a simple mistake. Now it won't output the slope, though. i input the four numbers, but when i click enter it doesn't output anything. is the system("pause") in the wrong place?
yes, move it to line 23.

:+)
are you sure? when i do that, i have to hit a key for the first cout to come up, and even after i input the numbers i don't get the slope.
hey just kidding, i had my lines mixed up. it works perfectly, thanks again
Topic archived. No new replies allowed.