r/cpp_questions • • Oct 27 '26

OPEN How can I learn to think logically when solving programming problems?

At college, I try to study as hard as I can; during computer science and programming classes, I make an effort to grasp every topic, and I practice a lot at home—even using an AI assistant—but it all feels like it’s for nothing. When it comes to practical assignments, I just can’t seem to formulate the code. What should I do?

0 Upvotes

11 comments sorted by

3

u/tickle-fickle Oct 28 '26

Start simpler then. If practical assignment are too difficult, and the process of translating what you have in mind into code is challenging for you, then you need to give yourself some grace and go slower.

What helped me a lot back in college is this silly exercise: role play as the compiler. Don’t try first to translate your thoughts into code, go the other way: translate the code into your thoughts, REALLY understand what is happening. The hope is that with enough training going one way, you’ll develop intuition on how to go the other way, the way that you actually wanna do. Like,

int main() {
int x = 7;
int y = 3;
x = x + y;
y = x - y;
std::cout << x << “, “ << y;
}

What would be the output?

Seriously, grab a pen and paper and just go line by line, track the value of each variable. And then run it, see if you’re correct. Then try harder examples, look for sample code of idk, bubble sort, and do the same. You got this!

1

u/Tw1lightt69 Oct 28 '26

At first, I start to understand how to do it, but it seems I’m doing something wrong.

1

u/tickle-fickle Oct 28 '26

DM me, I can help

5

u/Independent_Art_6676 Oct 28 '26

find problems that you can do with a bit of work. Not so hard it takes forever or that you need help, and not so easy that you can do it in your head before typing a line of code. Repeat. You get better by doing and thinking, and get away from the AI. AI is a great tool after you get better, but early on, its a distraction and a crutch and it will prevent you from thinking for yourself.

1

u/boring_pants Oct 28 '26

Try not using an AI assistant. The entire purpose of AI assistants is to avoid having to think. When you're trying to learn they're sabotaging you, not helping.

Team up with a classmate instead. Talk it through.

And don't be a perfectionist. Accept that your code probably isn't objectively good. Hack something together that solves the problem in front of you, no matter how forced it is, no matter how long and cumbersome the code ends up being, no matter how often you end up repeating yourself. Force yourself through the process.

1

u/Tw1lightt69 Oct 28 '26

how am I supposed to solve the problems then?

1

u/boring_pants Oct 28 '26

Without AI, you mean? The same way students learned to program just four years ago. By trying and thinking and writing code. By trying stuff and seeing if it works. By talking to your peers.

Can you elaborate on what the problem is? What is an example of the assignments you're trying to do and how far have you gotten on your own?

1

u/[deleted] Oct 28 '26

[removed] — view removed comment

1

u/boring_pants Oct 28 '26

But what happens when you try? Can you give an example? Paint the scene, describe to us the assignment, and what you do and when/how you get stuck.

1

u/Significant_Mix_8133 Oct 29 '26

Alot of good answers already. My advice is if you use AI don't use it to solve your issue. Tell the AI you want to do solve it yourself and share your thoughts with AI.

If you are really stuck and use AI aaaalways ask why.

Also if you write code ask AI what you can improve and why.

Don't worry the thinking will get better with time.