Struct Member Variable Problems

Joined
Jan 30, 2023
Messages
6
Reaction score
0
Hi, I am having a problem with declaring Struct Member Variables. What I want to do is create a Struct of Points in an x,y coordinate system wherein various bits of data related to the points are stored within the member variables of the Struct instances themselves. Here is an example of my code:


#include PointList.H

#include <cmath>

struct Point{
unsigned int x,y;
unsigned int IntValue(){
return x+y;
}
double YDivdedByX(){
return y/x;
}

double LRValue(){
return (y-((x+y)/2))
}
double OriginDistance(){
return sqrt((x*x)+(y*y))
}
double RadianValue(){
return asin((y / OriginDistance))
}

}

You might notice the OriginDistance value at the bottom. The problem with my code is that this seems to result in the member variables being treated as methods, not variables. I don't want to call methods from the struct, I want to access specific numeric values that are stored within instances of the struct. Can anyone help me with this?
 
Joined
Jun 25, 2023
Messages
2
Reaction score
1
Why don't you try creating a space using malloc in main function

Struct Point* point = malloc(sizeof(Struct Point));

And then take pointer of type Struct Point as parameter in all the functions.

double YdividedbyX(Struct Point* point){
return point->x/point->y;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top