Jason said:
Ok. The requirements say to write a function that reads pythagorean triples.
So the appropriate action when a pythagorean triple is not specified in the
input is to fail. Its just the same as when an integer isn't specified in
the input and operator>>(std::istream &, int &) fails. Why is this not
obvious?
You are funny, you know?
You start a thread which asks us to write code for something that looks
a lot like homework. Only after several answers it turns out that your
real problem is located in a very different section:
How to proceed if an input operator detects invalid input.
With no word have you addressed your real problem in the original
posting. You could eg. have asked
How do I proceed in in stream input operator if I detect an invalid
input? I know that eg reading an int may fail. How do I do the same
for my class? How do I force the stream to an invalid state? Or
are there better ways? What about throwing an exception?
Any thoughts welcome.
Instead you teach us a lot about phtagorean triplets which are really
unimportant to your real question. You would the very same problem
when you read eg. a date and get 30-feb-2004 as input.
To summarize: You don't ask the question you should ask but complain
that nobody is going to answer the question you didn't ask.
Here is how the function could be used in a program:
PythagoreanTriple triple;
while (cin >> triple)
cout << "PythagoreanTriple <" << triple.a << ", " << triple.b << ", " <<
triple.c << ">" << endl;
Please don't regard this as an amendment to the original requirements
because it isn't. The original requirements are complete. Everything I've
said here is obvious.
In your mind only.
Dream on.
Good luck to you.