# Return more than one answer for midpoint in a Point Class

• (2 Pages)
• 1
• 2

## 16 Replies - 969 Views - Last Post: 19 April 2011 - 05:57 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=228319&amp;s=83bc10ef86afd515ae6aa22a4373edde&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 clickspiker233

Reputation: 1
• Posts: 11
• Joined: 17-April 11

# Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 02:40 AM

I am having trouble on figureing out on how to return more than one value for x and Y. I know you can only have one return statement but i need to return a value for x and y. I am a little lost on how to do this.

This is what i have so far.

Point.cpp

```Point Point::midpoint(Point &midPointX, Point &midPointY)
{

Point middle;

midPointX = ((0 + middle.getX()) / 2);       // i am adding 0 because its supposed to go from point (0,0)

midPointY = ((0 + middle.getY()) / 2);       // i am adding 0 because its supposed to go from point (0,0)

return middle;
}
```

here is a sample output of the program. If more code is needed i to see if i am going wrong somewhere i can post it but when i comment out the midpoint stuff it compiles fine and just gives (0,0) as the midpoint

1st coordinate: 2
2nd coordinate: 2

The coordinates are: (2, 2)

The distance from invoking point (0,0)
to the coordinate you entered (2,2)
is: 2.82843 units

The midpoint between the invoking point (0,0)
and the coordinate you entered (2,2)
is: (0,0)

Is This A Good Question/Topic? 0

## Replies To: Return more than one answer for midpoint in a Point Class

### #2 janotte

• code > sword

Reputation: 990
• Posts: 5,141
• Joined: 28-September 06

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 02:54 AM

If you are passing by reference (i.e. prefixing & to the variable name) then the term return is the wrong word to use.

If you pass by reference then the changes you make to those variables will be available outside the function.

We need to see the code that calls this class method.

### #3 clickspiker233

Reputation: 1
• Posts: 11
• Joined: 17-April 11

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 03:02 AM

```
cout << "The midpoint between the invoking point (" << invokeX << "," << invokeY << ")" << endl;
cout << "and the coordinate you entered (" << pt1.getX() << "," << pt1.getY() << ")" << endl;
return 0;

```

its the line above the <---- it jumped to the next line when i posted

This post has been edited by clickspiker233: 19 April 2011 - 03:07 AM

### #4 janotte

• code > sword

Reputation: 990
• Posts: 5,141
• Joined: 28-September 06

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 03:08 AM

So you have a method that expects to be passed 2 arguments and you pass it zero arguments?

Do you think that might be a problem when said out loud like that?

### #5 clickspiker233

Reputation: 1
• Posts: 11
• Joined: 17-April 11

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 03:17 AM

janotte, on 19 April 2011 - 03:08 AM, said:

So you have a method that expects to be passed 2 arguments and you pass it zero arguments?

Do you think that might be a problem when said out loud like that?

maybe just a slight one, lol

### #6 TMKCodes

• D.I.C Regular

Reputation: 48
• Posts: 440
• Joined: 21-March 09

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 03:21 AM

You should call that midPoint function before printing and actually print the midPointX and midPointY variables, because midPoint will not return them, but actually modify them outside of the function.

This post has been edited by TMKCodes: 19 April 2011 - 03:22 AM

### #7 clickspiker233

Reputation: 1
• Posts: 11
• Joined: 17-April 11

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 03:24 AM

TMKCodes, on 19 April 2011 - 03:21 AM, said:

You should call that midPoint function before printing and actually print the midPointX and midPointY variables, because midPoint will not return them, but actually modify them outside of the function.

alright. i think i was about to ask something like that because i keep getting errors
and i have a

``` double midPointX, midPointY
```

so now i need to set the x equal to something and the y equal to something

im not sure how to do this but ill mess with it a little. i know i need to pass the
midpoint the numbers individually but when i do it says

main.cpp:49: error: no matching function for call to 'Point::midpoint(double&)'
Point.h:35: note: candidates are: Point Point::midpoint(Point&)
main.cpp:49: error: no matching function for call to 'Point::midpoint(double&)'
Point.h:35: note: candidates are: Point Point::midpoint(Point&)

This post has been edited by clickspiker233: 19 April 2011 - 03:28 AM

### #8 clickspiker233

Reputation: 1
• Posts: 11
• Joined: 17-April 11

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 03:44 AM

so i keep getting errors saying that there is no matching call to the

```main.cpp:49: error: no matching function for call to 'Point::midpoint(double&)'
Point.h:35: note: candidates are: Point Point::midpoint(Point&)
main.cpp:50: error: no matching function for call to 'Point::midpoint(double&)'
Point.h:35: note: candidates are: Point Point::midpoint(Point&)
main.cpp:60: error: no matching function for call to 'Point::midpoint()'
Point.h:35: note: candidates are: Point Point::midpoint(Point&)
main.cpp:60: error: no matching function for call to 'Point::midpoint()'
Point.h:35: note: candidates are: Point Point::midpoint(Point&)
```

### #9 TMKCodes

• D.I.C Regular

Reputation: 48
• Posts: 440
• Joined: 21-March 09

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 03:46 AM

```pt1.midpoint(midPointX, midPointY);

```

### #10 janotte

• code > sword

Reputation: 990
• Posts: 5,141
• Joined: 28-September 06

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 03:53 AM

To, almost, repeat myself.

You have a method that expects to be passed 2 arguments and you pass it 1 argument?

Do you think that might be a problem when said out loud like that?

### #11 clickspiker233

Reputation: 1
• Posts: 11
• Joined: 17-April 11

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 04:01 AM

TMKCodes, on 19 April 2011 - 03:46 AM, said:

```pt1.midpoint(midPointX, midPointY);

```

ok. i did that and i must have overlooked something simple. (at least im down to one error now)

this is what is giving the error

```pt1.midpoint(midpointX, midpointY);
```

this is where i set it to that

```
midpointX = number1; // the X value the user input
midpointY = number2; // the Y value the user input

pt1.midpoint(midpointX, midpointY);

```

This is the error:

main.cpp:52: error: no matching function for call to 'Point::midpoint(double&, double&)'
Point.h:35: note: candidates are: Point Point::midpoint(Point&, Point&)

here is where i output it

```
cout << "The midpoint between the invoking point (" << invokeX << "," << invokeY << ")" << endl;
cout << "and the coordinate you entered (" << pt1.getX() << "," << pt1.getY() << ")" << endl;
cout << "is: (" << midpointX << "," << midpointY << ")" << endl; // <----- output here

```

### #12 janotte

• code > sword

Reputation: 990
• Posts: 5,141
• Joined: 28-September 06

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 04:04 AM

Do you have a class called Point?
Did you declare midpointX to be an instance of that class? If not, why not?

EDIT
I need to be clearer. The above is not a rhetorical question. You do need to think about what datatype midpointX is and should be.

This post has been edited by janotte: 19 April 2011 - 04:06 AM

### #13 clickspiker233

Reputation: 1
• Posts: 11
• Joined: 17-April 11

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 04:09 AM

yes.

```class Point
{
public:

// many other declarations

Point midpoint(Point &midPointX, Point &midPointY);

private:
double _x;
double _y;
};

```

This post has been edited by clickspiker233: 19 April 2011 - 04:13 AM

### #14 clickspiker233

Reputation: 1
• Posts: 11
• Joined: 17-April 11

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 04:25 AM

Which is why im confused as to why im getting an error. it should work. but it doesnt

### #15 janotte

• code > sword

Reputation: 990
• Posts: 5,141
• Joined: 28-September 06

## Re: Return more than one answer for midpoint in a Point Class

Posted 19 April 2011 - 04:34 AM

So is midpointX an instance of the class Point?
Or is midpointX a private member variable of an instance of that class?