New answers tagged

8

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. ...


8

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 ...


5

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>).


2

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