P
Phlip
Jeff said:Hi Pmb, ( and all you C++ guys too ) [ Posted & e-mailed ]
You showed, " sum = u + v; ".
And in your e-mail to me you showed:
cin >> "Enter z = x + i y: " >> z;
Whoever wrote that is leading you astray. 'cin' is not some kind of magic
prompt system. The string literal will turn to a constant char pointer,
which won't compile.
Try
cout << "Enter z = x + i y: ";
std::string zee;
std::getline(cin, zee);
That interprets linefeeds as turnaround characters. But then you must parse
zee and get the integer out of it.
I'd be nice if one could say:
cin >>
"Enter z, ( in the form: Real + Imaginary ): " >> z;
Then the user could simply type in something like:
5 + 6
But you can't overload the + symbol like that,
because it reacts to the type of the operands,
which, in this case, are not even reals,
much less complex. ( They are integers )
The user can't type + unless you parse it. If you do, you get to decree what
it does.
Could that be solved by
using something other than the + symbol ?
Correct me if I'm wrong here C++ guys,
but I think the only solution is
to use string input like this:
float Real; String A_String_Operator; float Imaginary;
cin >>
"Enter z,"
" ( in the form: Real + Imaginary, "
" spaces required ): " >>
Real >> A_String_Operator >> Imaginary;
Are you compiling and testing these things before asking? Always edit,
compile, and test in tiny little cycles, adding one ability at a time.