Hi there,
I am reading and entering the code from O'Reilly's Practical C++ Programming book. my g++ is complaining of syntax errors in example 7-1 from chapter 1. Might somebody explain why I am getting these errors.
Here are the errors:
--- snip ---
% g++ -g -Wall -o calc.exe calc.cpp
calc.cpp: In function `int main()':
calc.cpp:18: warning: suggest parentheses around assignment used as truth value
calc.cpp:19: syntax error before `+='
% g++ -v
Using builtin specs.
gcc version 2.95.4 20020320 [FreeBSD]
%
--- snip ---
Code:#include <iostream> int result; // the result of the calculations char oper_char; // operator the user specified int value; // value specified after the operator int main() { result = 0; // initialize the result // Loop forever ( or till we hit the break statement) while (true) { std::cout << "Result: " << result << '\n'; std::cout << "Enter operator and number: "; std::cin >> oper_char >> value; if (oper_char = '+') { return += value; } else { std::cout << " Unknown operator " << oper_char << '\n'; } } return (0); }



LinkBack URL
About LinkBacks


