J
Johs
In Pratical C++ Programming by Steve Oualline (O'Reilly) I found this
code example:
#include <iostream.h>
int result; // the result of the calculations
char oper_char; // the user-specified operator
int value; // value specified after the operator
int main()
{
result = 0; // initialize the result
// Loop forever (or till we hit the break statement)
while (1) {
cout << "Result: " << result << '\n';
cout << "Enter operator and number: ";
cin >> oper_char;
cin >> value;
if (oper_char = '+')
result += value;
} else {
cout << "Unknown operator " << oper_char << '\n';
}
}
return (0);
}
In the if statement only one '=' is used:
if (oper_char = '+')
Should that not be '==' or is there some exception in C++ where you can
compare chars with only '='?
Later in the text they type 'if (oper_char = '+')' again so it seems
that its not a typo - unless the O'Reilly author has been in a rush.
code example:
#include <iostream.h>
int result; // the result of the calculations
char oper_char; // the user-specified operator
int value; // value specified after the operator
int main()
{
result = 0; // initialize the result
// Loop forever (or till we hit the break statement)
while (1) {
cout << "Result: " << result << '\n';
cout << "Enter operator and number: ";
cin >> oper_char;
cin >> value;
if (oper_char = '+')
result += value;
} else {
cout << "Unknown operator " << oper_char << '\n';
}
}
return (0);
}
In the if statement only one '=' is used:
if (oper_char = '+')
Should that not be '==' or is there some exception in C++ where you can
compare chars with only '='?
Later in the text they type 'if (oper_char = '+')' again so it seems
that its not a typo - unless the O'Reilly author has been in a rush.