New to programming: How to call a structure’s variables in a function and then update them? (C++) [closed]

Seems to me that you want this:

#include <iostream>

struct Point {
    float X;
    float Y;
};

struct Line {
    Point Point1;
    Point Point2;
    float slope;
    float yInt;
    float lineLength;
    float Angle;
};

Line getLine()
{
    Line var;

    std::cout << "enter the first point:";
    std::cout << "\nEnterX and Y coordinates separated by spaces:";
    std::cin >> var.Point1.X >> var.Point1.Y;

    std::cout << "enter the second point:";
    std::cout << "\nEnterX and Y coordinates separated by spaces:";
    std::cin >> var.Point1.X >> var.Point1.Y;

    return var;
}

It doesn’t really make sense for a Point’s coordinates to be in only one float, as that would only be one dimension. I modified the Point class so that each Point would have an X and a Y float. Next, the >> operator only reads one int, so you need two. Bye!

Leave a Comment