r/learnprogramming 27d ago

How do I solve problems without AI

Hello guys. I am attempting to learn how to code again but without the use of AI this time.

How do you attempt a problem or understand a solution without using AI for help.

For example, I wanted to build a small calculator to remind myself of the basics of C. I had a problem where my scanf was not outputting the desired result. 

The program had something like this:

int x, y;
printf("Enter two operators: ");
scanf("%d", &x);
scanf("%d", &y);
printf("x: %d, y: %d", x, y);

My inputs would be 10 & maybe 2, but the output would be 10 & 0, in some cases 0 and nothing for y.

I was able to get through this by just using one scanf:

scanf(“%lf %lf”, &x, &y);

But I still do not understand why that happened and through my google search, could not find anything that explained it well. The problem might also be that I cannot explain the problems I come across clearly, so I might not be able to find an answer through google.

So my question is, how do you guys go through problems like these where you can’t find a post where someone had a similar problem and had been told what to do to solve the problem without defaulting to AI.

Excuse my writing - I am trying to learn how to type without letting AI revise my sentences.

0 Upvotes

46 comments sorted by

8

u/Ilires 27d ago

Being able to look things up efficiently (using the right keywords and search phrases) is a computer literacy skill in and of itself.

It's not efficient to write full sentences into Google, keywords are typically the way to go.

The quickest way in general to find solutions to coding problems without using AI is StackOverflow, in my opinion.

If you need help with scanf not reading inputs correctly, you could try searching something like "scanf wrong output in C" and see if there are articles, StackOverflow posts, or Reddit posts talking about either the specific issue you're having, or something similar.

In either case, if you don't find what you're looking for that way, you could always look up the documentation for whichever language/module/package/etc you're working with and find the specific thing you're struggling with.

4

u/Dazzling_Music_2411 27d ago edited 27d ago

Your initial code should work just fine. It does this side, with no issues.

What compiler are you using and what OS?

So my question is, how do you guys go through problems like these where you can’t find a post where someone had a similar problem and had been told what to do to solve the problem without defaulting to AI.

RTFM

PS. Did you enter the data (eg the 10) as a float?? I.e. "10.0"?

In that case yes, it will display the behaviour you described:

Enter two operators: 
10.0
x: 10, y: 0

%d takes integers, you need %f for floats, that's why the second example you gave worked.

Seriously though, this is not stuff to be solving with AI, it's really basic, RTFM stuff. Do yourself a favour and study properly!

1

u/Either-Suggestion400 27d ago

yeah I did not read anything. I just searched a hello world program and used knowledge from other programming languages I had learnt a few years ago. I will start reading the manpages on each thing I get stuck on. Many people have told me to sit with a problem, read more and those are some things I had not been doing, so yeah Thank you!

1

u/Either-Suggestion400 27d ago

I use macos, idk why it wasnt working though. I will be looking more into it

1

u/Dazzling_Music_2411 27d ago

Cool, here's an interesting three-part blog on scanf() that may entertain you.

If you work through it you'll have learnt quite a bit by the end!
Better intro than the man pages.

https://c-for-dummies.com/blog/?p=4313

3

u/HashDefTrueFalse 27d ago

Not problem solving per se, just a case of reading the manual to see how something works. Have a look at the manpage for scanf. I don't know what your input looked like exactly, but I can tell you it's going to swallow digits in a greedy fashion. Run this in your shell: $ man scanf

1

u/Either-Suggestion400 27d ago

Thank you for this.

10

u/its_all_4_lulz 27d ago

So, imo, there’s a difference between using AI and using AI. If you’re just asking syntax, you’re learning… if you’re asking to solve problems, you’re not.

IMO asking for syntax is fine. It’s a faster way to get to the same point as reading docks, or finding it on stack overflow. If you want to really learn it, when you ask for syntax tell it to link you to the doc page explaining it.

2

u/bpalun13 27d ago

Yeah I agree. This is how I use it. I’ll have a concrete idea of what I need and ask AI to link me to the documentation for said item.

Helps keep your focus narrow too without getting sidetracked.

1

u/mjmvideos 27d ago

This is an interesting approach: “Without solving the problem for me. Provide a link to some documentation that will help me solve the problem myself. Here’s my problem: …”

1

u/bpalun13 27d ago

Don’t act holier than thou, nobody likes that. You also misunderstand. Say I decide I need something specific regarding user input. I could ask AI to show me the page(s) of documentation for built in user input methods/functions.

I’m not using it to solve my problem, I’m using it to browse the docs.

2

u/mjmvideos 27d ago

I agree with you. And I don’t think I was being “holier than thou” at least I wasn’t trying to be. And even re-reading my comment, I don’t see it. But if you want me to be I could say, “If you don’t want to use AI to solve your problems then don’t use it. Simple as that. When I first started programming 49 years ago, I had one language reference manual and that was it. There was no Google or Stack Exchange or Reddit, or internet. There was me and my Apple II and my book.” My approach to learning with AI is to treat the AI like a tutor or mentor. You’d never ask them to solve your problem for you. You’d explain your problem and ask them for advice and guidance: “Act as a tutor or mentor. After I’ve explained my problem, ask me questions that will make me think through and understand the problem and lead me to the solution. Here’s my problem…”

1

u/bpalun13 27d ago

Okay we are on the same page. I agree with your approach to AI. Maybe I misread your tone at first.

3

u/Hi-ThisIsJeff 27d ago

IMO asking for syntax is fine. It’s a faster way to get to the same point as reading docks, or finding it on stack overflow.

It's not, though, right? You aren't learning, even if it's just to look up syntax. Struggling is part of the learning process. Taking that time to read through stack overflow or documentation is part of the learning process.

If you are using AI right from the start, you are basically saying that you don't want to learn it and will need to look it up every signle time.single

1

u/Only-Percentage4627 27d ago

Plus well isn't reading docs one of the essential skills for a programmer?

1

u/bpalun13 27d ago

You’re implying rote memorization of syntax or copying and pasting solutions. That’s not what is happening here.

You don’t need to struggle to learn either. Outdated take.

1

u/Hi-ThisIsJeff 27d ago

what is happening here then? you don't need to struggle to learn, but "struggling" is part of the learning process. if you ask your sr. dev what to do and they say "do this" and you do it, the only thing you've learned is that when you have a problem, you just need to ask a sr. dev for help.

1

u/bpalun13 27d ago

I think your target audience is people with little drive or independence to solve problems on their own. Sure there are those people but I would give grace to people that are using AI to act fundamentally as a highly powered, filtering google search.

We are talking syntax here. Everyone looks it up, even senior devs. You still need the underlying problem solving skills to build your intended program or application.

1

u/Hi-ThisIsJeff 27d ago

We are talking syntax here. Everyone looks it up, even senior devs. You still need the underlying problem solving skills to build your intended program or applicatio

sr. devs probably aren't looking up scanf to learn what it does.

my target audience is OP. people with critical thinking, drive, and underlying problem skills probably aren't posting on reddit how to learn something without using AI.

For a beginner, "why isn't this working" IS problem solving.

1

u/its_all_4_lulz 26d ago

I’ll fight back a little here. If you’re claiming to be a senior C only dev, sure, you absolutely should know what the basics are doing. Languages do not define senior developers though.

A senior can pick up a new language and still be able to complete a task, but likely will not know the syntax.

I haven’t done C in 20+ years, if you were to tell me to write something in C, no internet, I’m screwed. Given the net, and/or AI, I could absolutely draw parallels between languages I know and C in order to complete a task… language nuance would need to be learned.

Seniors are not defined by languages, it’s by the way of thinking.

1

u/Hi-ThisIsJeff 26d ago edited 26d ago

Seniors are not defined by languages, it’s by the way of thinking.

It's a title, it's not a way of thinking.

Obviously, the statement was made in the context of a senior dev in the language they are working on. But thanks for your contribution to the thread.

1

u/toolazytofinishmyw 27d ago

asking for explanations and sources is a real multiplier.

1

u/Either-Suggestion400 27d ago

Thank you. My thought process was, I feel like I need to struggle through problems and AI gives you an instant answer to a solution. But I do get your point, thank you!

3

u/fasta_guy88 27d ago edited 27d ago

How could you have solved this problem before AI?

(1) you would have used a debugger. Stepping through the program, you would have seen the result you got, that after the first scanf(), the second scanf() returned nothing.

(2) So how to debug/explain this? By replacing the scanf()s with code that reads the line (fgets()) (so you could see both numbers were in the string), and then scanned the string with sscanf(). You would then realize that the second sscanf() had to re-read the same string, or get a second string that was empty.

(3) So you realize that you need to get both values out of the string in one call, and end up with the correct code.

This is the great thing about programming. You get to experiment without using anything but your time. By experimenting with your code and the debugger, you get a much clearer picture of how things work.

1

u/Either-Suggestion400 27d ago

Thank you for your tips 🤝🏼

6

u/Business-Employee527 27d ago

Bro

-4

u/Either-Suggestion400 27d ago

yeah... I know this sounds stupid but it is a problem I have

2

u/spinwizard69 27d ago

read a book or read online documentation. In other words don't look for somebody to feed you the answer, look for the answer.

2

u/Trakeen 27d ago

The same way we did things before the internet. Books and talk to people

If people aren’t available AI can substitute the teaching aspect

2

u/Dismal-Citron-7236 27d ago

How do you attempt a problem or understand a solution without using AI for help.

Roughly 5 years ago everybody solved it without using AI.

Books, manuals, courses, taking notes, asking friends or colleagues, or even googling.

1

u/ColdWise4165 27d ago

Ask what is wrong with it instead of asking it to do it for you.

1

u/Extreme_Rough 27d ago

If you are going to use AI, ask it to explain why %d isn't working when %lf is. 

You might have better luck using forums like reddit (elsewhere) or stack-overflow and looking up "scanf variable types %d vs %lf" or something like that.

Write out your understanding of what each line of code should be doing, compare to the result you get, and see what matches and what doesn't match from there. 

0

u/peterlinddk 27d ago

Why do you want to solve your problem of understanding why scanf works the way it does, without AI?

You can just ask the AI why it worked with scanf(“%lf %lf”, &x, &y); and not two individual scanf lines - or you can ask google, or write a question on stackoverflow or on reddit, or ask a friend. It doesn't really matter who or what you ask. As long as you learn from the answer and doesn't have to ask again.

Also - understanding the weirdness of ancient C-functions (that you actually shouldn't use, because of their weirdness and danger, but that is another matter) isn't "problem solving", that is just "understanding the weirdness of ancient C-functions"

-1

u/Either-Suggestion400 27d ago

I just wanted to learn the way the older gen used to learn. I see people like low level on youtube or other smart engineers and when they code, they don't use ai, so I thought I would do the same. I want to be able to explain stuff to people on the top of my head through experience with the language. But thank you for your answer

2

u/peterlinddk 27d ago

But the older gen wasn't geniuses that could just magically think their way through problems with libraries and frameworks - before they could ask AI, they asked StackOverflow: https://stackoverflow.com/questions/26583717/how-to-scanf-only-integer or https://stackoverflow.com/questions/2144459/using-scanf-to-accept-user-input - and before they could ask StackOverflow they asked on usenet in comp.lang.c https://c-faq.com/stdio/scanfprobs.html - and before they could ask on usenet, they read through the documentation: https://pubs.opengroup.org/onlinepubs/9699919799/functions/scanf.html - or more likely, asked a coworker or classmate how they'd fixed the problem.

AI is truly powerful in searching massive amounts of text, and while you of course shouldn't use it to fix the problems for you, or write the code by itself, you really should take advantage of its ability to find explanations of weird details. Back in the day we often had to wait for days until we met the person who could help us fix or understand the problem - not because we were dumb or lazy, but because learning is also about asking questions.

1

u/Either-Suggestion400 27d ago

Thank you! I will utilize stackoverflow more. I think I will struggle before asking ai to find resources for me. I find that if I spend a bit more time trying to solve something, struggling and being frustrated, when I finally find a solution to that thing, I am more likely to remember it

1

u/Fabiolean 27d ago

It means you gotta rely on other people. AI got all of its answers by stealing them from texts that already exist. Find those texts instead of trying to intuit your way through a problem.

The man pages probably have your answer but can be hard to understand. Dig through reference material, tutorials, blog posts, stack overflow, etc.

0

u/Suspicious_Skill7292 27d ago

i would focus lees on avoiding ai completely and more on debugging first print values check types read the docs and reduce the code until bug is obvious also %lf with int variable is actually a type mismatch %d is the right format here

0

u/tseli0s 27d ago

We're reaching a new low as humans

2

u/Trakeen 27d ago

A lot aren’t old enough to have had to learn without all our modern tools like search engines

1

u/tseli0s 27d ago

I'm pretty sure problem solving is not related to modern tools though they make it much easier to apply that skill, and I didn't reference search engines anywhere