why doesnt display?

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
#include <iostream>
....
    Rectangle r;
    Point xny;
Asking user for info


....

// I am trying to display the x and y... but it show x:0 and y:0
 //Display the x and y coordinates
    
    cout <<"X: " << xny.x <<" " << "Y: " << xny.y << endl;
    
    return 0;
}
Point findarea (Rectangle r)
{
    const int midpoint_x = ( r.uppper_left.x + r.lower_right.x ) / 2;
    const int midpoint_y = ( r.uppper_left.y + r.lower_right.y ) / 2;
    
    const Point its_center = { midpoint_x, midpoint_y } ;
    return its_center;
}
Last edited on
bump?
You haven't shown the important part; where those values are actually gotten from.
I got those info from main function. the infor will be input from user
Please show how you do it, as that part might be the problem.
#include <iostream>

using namespace std;


struct Point
{
    int x;
    int y;
};
struct Rectangle
{
    Point uppper_left;
    Point lower_right;
};
Point findarea (Rectangle r);


int main ()
{
    //remane the Rectangle to r
    Rectangle r;
    Point xny;
    //Welcome the user to program
    
    cout <<"Welcome" << endl;
    
    //Ask the user for information
    
    cout <<"What is the upper left coordinate do you like to input" << endl;;
    cin >> r.upawdadpper_left.x >> r.uppper_left.y;
    
    cout <<"What is the lower right coordinate do you like to input" << endl;
    cin >> r.lower_right.x >> r.lower_right.y;
  if (r.uppper_left.y > r.lower_right.y)
    {
        cout <<"Error" << endl;
        cout <<"The upper right should be bigger than lower left"<< endl;
        
        if (r.uppper_left.y == r.lower_right.y)
        {
            cout <<"Error" << endl;
            cout <<"Your upper left y cannot be same as lower right" << endl;
            cout <<"It will create a horizontal line"<< endl;
        }
    }
    //Display the x and y coordinates
    
    cout <<"X: " << xny.x <<" " << "Y: " << xny.y << endl;
    
    return 0;
}
Point findarea (Rectangle r)
{
    const int midpoint_x = ( r.uppper_left.x + r.lower_right.x ) / 2;
    const int midpoint_y = ( r.uppper_left.y + r.lower_right.y ) / 2;
    
    const Point its_center = { midpoint_x, midpoint_y } ;
    return its_center;
}
Last edited on
You are printing the value of xny, which has never received a value anywhere in your program.
i dont get it. I have Point Structure is midpoint_x and y store in x and y?
can you show me how?
Last edited on
Consider this much simpler but very similar example:
1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main() {
  int r;
  int xny;

  std::cout<<"Welcome"<<std::endl;
  std::cin>>r;
  std::cin<<"xny is: "<<xny<<std::endl;
}

Can you see why xny would not be printed here?
I see it because r is one who have value from user and xny come from no where
Topic archived. No new replies allowed.