good afternoon,
i'm having some trouble with pass by reference using structs. So far I think i'm on somewhat the right track but the portion that's giving me trouble at the moment is the PrintVector() function. I've removed a lot of the items to see if a blank slate would help me solve this but I have yet to wrap my head around this problem. i'm not sure where to begin with it and I've spent the better part of my morning on this one section my main problem is how to get the other two functions to pass their values onto the PrintVector() function as every time I've tried this I can't seem to get it right. My main error seems to be that I have too few arguments to call the function in a pass by reference, but I don't see where all the arguments come into play in the PrintVector() function. any nudge in the right direction would be super appreciated. thank you
Code:
#include<stdio.h>#include<stdlib.h>
#include<math.h>
typedef struct
{
double x;
double y;
double z;
} Vector;
void AddVector(const Vector *Pv1, Vector *Pv2)
{
Vector newVectorAdd;
newVectorAdd.x = Pv1-> x + Pv2-> x;
newVectorAdd.y = Pv1-> y + Pv2-> y;
newVectorAdd.z = Pv1-> z + Pv1-> z;
}
void SubtractVector(const Vector *Pv1, Vector *Pv2)
{
Vector newVectorSub;
newVectorSub.x = Pv1-> x - Pv2-> x;
newVectorSub.y = Pv1-> y - Pv2-> y;
newVectorSub.z = Pv1-> z - Pv1-> z;
}
void PrintVector(const Vector *Pv1, Vector *Pv2)
{
Vector ;
AddVector();
printf("Addition Result: (%.02lf, %.02lf, %.02lf)", add.x, add.y, add.z);
SubtractVector();
printf("Subtraction Result: (%.02lf, %.02lf, %.02lf)", sub.x, sub.y, sub.z);
}
void main()
{
Vector v1, v2;
printf("Enter the first value of the first vector in meters (X): ");
scanf_s("%lf", &v1.x);
printf("Enter the second value of the first vector in meters (Y): ");
scanf_s("%lf", &v1.y);
printf("Enter the third value of the first vector in meters (Z): ");
scanf_s("%lf", &v1.z);
printf("Enter the first value of the second vector in meters (X): ");
scanf_s("%lf", &v2.x);
printf("Enter the second value of the second vector in meters (Y): ");
scanf_s("%lf", &v2.y);
printf("Enter the third value of the second vector in meters (Z): ");
scanf_s("%lf", &v2.z);
PrintVector(v1, v2);
system("pause");
}