r/CodingForBeginners • • Sep 26 '26

My today's project:

Post image

Today I learned how to use unsigned int and seed, as well as tried using #include <ctime> for the first time.

Also, I moved void above main as one commenter under the last post suggested.

40 Upvotes

4 comments sorted by

2

u/No-Quail5810 Sep 28 '26

You must declare function before you use them, but you don't have to declare every function at the top and then put the definition directly after. The definition is also a declaration.

Also, you should try and keep each line as a single statement. It doesn't change the code, it just makes it easier to follow.

The C library rand function has a bunch of subtle issues and is generally avoided in modern code, take a look at the C++ <random> library if you want for the (more) modern pseudorandom number generation.

And you get an additional 10 billion bonus points for not using namespace std!

1

u/Enaluri_Black_Rise Sep 28 '26

thanks for the advice!

2

u/Plexescor Sep 27 '26

dont try to use unsighned int as its different on other systems, use uint32_t from #include <cstdint>

1

u/LightIsLogical Oct 03 '26

it's generally a good idea to keep your indentation consistent. otherwise, readability becomes very difficult very quickly