Theory
Common mistakes
When the program doesn't build or calculates something other than you expect, check this list first.
Common mistakes
- A wrong format.
format '%d' expects argument of type 'int', but argument 2 has type 'double': adoubleis printed with%f, along longwith%lld. GCC writes the right format under the error. - Integer division.
(g1 + g2 + g3) / 3throws the fraction away before it is stored in thedouble. At least one side must be adouble:3.0or(double)sum. - Overflow.
long long x = 100 * 365 * 24 * 60 * 60;is still worked out withint. Write100LL * .... - A comma instead of a dot. In code,
double x = 7,5;givesexpected identifier or '(' before numeric constant. When typed as input,7,5getsNot valid: enter a number with a dot, e.g. 7.5. - A forgotten
#include "input.h".implicit declaration of function 'read_int'. - A forgotten
target_link_libraries. Compiling succeeds, but the linker reportsundefined reference to 'read_int':CMakeLists.txtis missingtarget_link_libraries(... PRIVATE course_input). - An unused variable.
unused variable 'average' [-Werror=unused-variable]: either use it or delete it. "A"instead of'A'.%cexpects one character in single quotes. With"A"GCC reportsargument 2 has type 'char *'.