Need help with functions

Write your question here.
Write a main that test for slope() and midpoint()
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
#include <iostream>
using namespace std;
double slope(double x1, double x2, double y1, double y2)
{
	double delta_x = x2 - x1;
	double delta_y = y2 - y1;
	double slope = delta_x/delta_y;
	return slope;
}

void midpoint(double x1, double y1, double x2, double y2, double& xMidpoint, double& yMidpoint) 
{
	double xMidpoint = (x2+x1)/2.;
	double yMidpoint = (y2+y1)/2.;
	double Midpoint = xMidpoint/yMidpoint;
}

int main ()
{
double x1, x2, y1, y2;
	cout << "Enter your x1 point: ";
	cin >> x1;
	cout << "Enter your y1 point: ";
	cin >> y1;
	cout << "Enter your x2 point: ";
	cin >> x2;
	cout << "Enter your y2 point: ";
	cin >> y2;
return 0;
}
Last edited on
Next time when you post your code, make sure to ask the question that you have.

I'm simply going to guess what you are trying to do.

In main, you need to call your slope and midpoint functions. I'm also going to guess your midpoint function needs to return a double and actually return the midpoint that it calculates.

Calling a function looks like this.

1
2
3
4
5
6
7
8
9
10
11
12
int foo(int a, int b, int c)
{
    return a + b + c;
}

int main()
{
    // Instead of passing 1, 2, and 3, I could also 
    // set variables to these and pass them in the function.
    int fooReturnValue = foo(1, 2, 3);
    return 0;
}
Topic archived. No new replies allowed.