can anyone help me actually put the values into the structure..?

#include <iostream>
#include <string>
#include <sstream>
#include <cmath>

using namespace std;

struct x {
double x1;
double x2;
double x3;
};

int main()
{
struct y {
double a;
double b;
double c;
};

cout << "Input values of a, b, and c.\n";
cin >>y.a >>y.b >>y.c;

for (int i = 1; i <= 10; ++i);
{
if ((b * b - 4 * a * c) > 0))
cout << "x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a)" &&
cout << "x2 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a)";

if else ((b * b - 4 * a * c) = 0)
cout << "x = ((-b + sqrt(b * b - 4 * a * c)) / (2 * a)";

if else ((b * b - 4 * a * c) < 0))
cout << "x1 = ((-b + sqrt(b * b - 4 * a * c) * sqrt (-1)) / (2 * a)" &&
cout << "x2 = ((-b + sqrt(b * b - 4 * a * c) * sqrt (-1)) / (2 * a)";

}

return (0);

}
You need to declare 'x' and 'y' objects in your main function.

 ``12`` ``````x Xstruct; // x is a type y Ystruct; // y is a type ``````

so for an example, you'll have

`cin >> Ystruct.a >> Ystruct.b >> Ystruct.c;`
Last edited on
If you really want to use a structure, you could use this sort of syntax:
 ``1234567`` ``````struct coefs { double a; double b; double c; }; coefs y;``````

This basically says that y is a specific instance of the coefs structure.

But still, in this case it just means that throughout the program you need to put "y.a" rather than just "a", and doesn't seem to offer any great benefit.

There are a few syntax errors throughout the code.
This line should not end in a semicolon:
`for (int i = 1; i <= 10; ++i);`
... but on the other hand, I'm not sure why it's there at all.

The "if" statements should group the statements which depend on it using braces like this:
 ``12345678910`` `````` if (condition) { print first root; print second root; } else if (condition) { etc. } etc.``````

Last edited on
Topic archived. No new replies allowed.