New answers tagged


Questions: Can I make this code shorter? Yes Is it possible to do? Yes If it is, how? By using functions. You can move common code to a named function. Notes This is C code not C++. Sure it compiles with a C++ compiler (so does a lot of C). C++ is a style of programming, you are not using the C++ style you are using the C style of programming. ...


There is no better way to say this, but your code is shockingly bad. I will just provide a short summary of the things that can be improved: #include headers like everyone else does, don't forward declare standard library functions. Since you tagged the post C++, use C++'s iostream functionality; it gives you type safety. Split your program into several ...


This is not a full review, but try using functions actually used in modern C++. There is no point in using printf() and scanf(), as they are just in the language for C-portability. std::cout and std::cin would be the C++ equivalents (you have to #include <iostream>).


Formatting I'd recommend looking at the accepted PSRs - e.g. PSR-1, PSR-12. Updating the code to comply with them will help make the code readable and consistent with idiomatic PHP code. Maybe this is just a copy-paste issue, but even if you don't strictly follow PSR-12 please indent nested lines within blocks. Array syntax As of the time of writing, PHP 7 ...

Top 50 recent answers are included