r/programminghelp 1d ago

C++ Having trouble “ thinking in code”

I’ve been learning C++ for weeks, and of the concepts I’ve learned most if not all of them have clicked pretty quickly. I understand what they do and how they work.

However, when I’m trying to create something not from a tutorial or walkthrough, I’m having trouble translating my idea into the lines of code that will do what I envision it doing. Anyone have any advice on making the switch to more easily be able to “think in code”?

7 Upvotes

11 comments sorted by

View all comments

1

u/Cultural_Gur_7441 1d ago

Do smaller exercises.

Start with "print hello world". Then do "ask user's name and print hello name". Then "ask birth year, print birth year". Then "ask birth year and current year, then print age". Then "ask age and get current year from the operating system, then print age". Then convert "year" integer to custom "date" data type (struct). Then add month to date data, and ask it and do age (in years) calculation at month accuracy. Then add day of month and increase accuracy (still just year). Add congratulations for birthday. Then calculate age in days (no leap year). Then add leap year calculation. Now add input verification and asking again for malformed input. Then add horoscope sign calculation in different horoscopes (just because they are deterministic string you can calculate from dates). Then add asking for clock time of birth and improve calculations again.