I am trying to program a Cartesian class with a friend extraction operator function. When I try to compile it I can't because of a problem in the implementation section. Can anyone tell me what algorithms I need to use to fix this?
Okay I fixed that, but now my program's output is
(6.95319e-310, 0)
(6.95319e-310, 0)
Why didn't it ask for the user to input values for the coordinates?
Why didn't it ask for the user to input values for the coordinates?
Input should be requested by the executable.
The issue is the assignment of garbage values to the member variables of the argument. Throughout the execution of the function that overloads the extraction operator, only the variables declared within its compound statement are set to the input. In other words, the function does not have the desired affect on the given object. This can easily be solved with the replacement of the right operands of the extraction operator with num.x and num.y.
1 2
in >> num.x;
in >> num.y;
You've seemingly confused non-reference variables with reference variables. Know that they do differ.
Okay so I fixed that and changed some other parts of my code a bit, but now I get an error for the x=c and y=d portions of the declaration section saying x and y don't name types. What should I do?
Whoops, I didn't notice at first that you had operator>> defined.
In that case, you should just be able to do
1 2 3 4 5 6
int main()
{
Cartesian coord1, coord2;
cout << "Please enter the first coordinates: ";
cin >> coord1; // When inputting, input just the numbers, e.g. 5 6 (not (5,6))
// ...
What do you mean by "it doesn't ask for user input"?
Does it just completely skip the cin >> coord1; and cin >> coord2; lines?
Does the program pause without the text "Please enter the first coordinates in the form x y: " showing up?
If it's the latter, try adding a cout << flush; between lines 44 and 45, and also between lines 46 and 47.