How do I know what to write

Pages: 12
Okay for a long time now, I've wondered when it comes down to righting a programme, HOW DO I KNOW WHAT TO WRITE? How do I know what words/terms/etc will C++ accept? I've followed plenty of c++ video tutorials, read a whole lot did a course a few years back but to this day I still can't quite understand what to write? How do I start? I feel like whenever I want to do something it has to be of someone else's code and I'm tired of that. "Okay now let me just change this word to this and voila I've created an application. Yeah alright, all I did was edit a damn word", and quite frankly that isn't teaching me anything at all.

I've done the hello world a billion times but still if I was to write it without seeing code first I would not be able to do it. Most of the time when I look through code I can tell at least a majority of time what it does. But if it comes to me trying to write my own programme no matter how simple it is I just can't start because I don't know the terms c++ accepts or how it wants it layed out. I don't know how to explain this but I'm hoping you guys will understand. This is what is holding me back and has haunted me since the stone age and I feel unless I get the answer I just can't move on.

Is there anybody else here who understands where I'm coming from with this?
Your question is pretty hard.
Coding can be broken down into two general steps:
1. Deciding on a series of steps that you want the computer to follow. E.g. "compute the square root of of the sum of the squares of two numbers".
2. Translating this into a notation that the computer can understand. sqrt(x*x+y*y)
If you can't do #1, the problem is at such a fundamental level that I can't help you there. Unless there are programming teachers on the forum, none of the other members will be able to help you, either.
But from what you've said, your problem seems to be with step #2. Have you tried first writing down your algorithm in plain English? Writing it in a syntax you're more familiar with, such as traditional mathematical notation, may help you organize your thoughts at first.
Try defining in English a function that takes three numbers (a,b,c) and returns how many solutions ax2+bx+c=0 has. Don't worry about the syntax, just write it however you feel is most natural to you. Then try to translate small bits of it to C++; no need to do it from memory, feel free to check your book(s)/sources if you need to. Eventually, try translating it completely.

PS: When you're done, tell us you well did.
Last edited on
I've followed plenty of c++ video tutorials, read a whole lot

I find video tutorials are not good for beginners. Instead of "following along" and "reading", I would suggest picking up a tutorial and examining it. That is, for each line of code, look at it, understand it, and tell yourself what it means in plain English.

One thing is troubling about this, though. You say you've done a course, yet you can't do a Hello World program from memory? I don't know what to say to that...

Well, here's a C++ program that's even simpler than Hello World:

1
2
3
4
int main()
{
   return 0;
}


First, examine what line 1 does. Then, examine what line 3 does. What do they do in plain English? After you understand that, I would suggest examining a tutorial on C++ variables. Then, add one line of code to this program and tell yourself what it does in plain English. This may slowly help build your confidence.

EDIT: I should remember to refresh before posting :S
Last edited on
I find that the best way to start learning a language is to play with the coding and see what happens. For example, in that simple "Hello World" program I messed with the output. Then, never having been exposed to header files before, removed the iostream file. Then I realized that cout was part of that file. Life then went normally.
You can't just look at other people's code and expect to know how to code. Before you can examine other people's code, you need to understand the syntax and how the language functions.
Stop watching YouTube tutorials. It's a terrible way to learn. Try the cplusplus.com tutorial.

http://www.cplusplus.com/doc/tutorial/
Thanks for the replies, I think what confuses me the most is how and when do I know where to use things like commas, semi colons, brackets and so on. When do I get to the stage were I'll know how to use them and when? Could it be cause I'm weak at Maths I'm not understanding simple concepts like these? What I'm trying to say is no matter how many tutorials you'll go through you'll never really be able to independently write a programme of your own with your own code, it'll always be someones else's if you sort of get what I mean? You'll always remember, okay so that's how he done it in his programme so I just follow the same thing.
Thanks for the replies, I think what confuses me the most is how and when do I know where to use things like commas, semi colons, brackets and so on. When do I get to the stage were I'll know how to use them and when? Could it be cause I'm weak at Maths I'm not understanding simple concepts like these? What I'm trying to say is no matter how many tutorials you'll go through you'll never really be able to independently write a programme of your own with your own code, it'll always be someones else's if you sort of get what I mean? You'll always remember, okay so that's how he done it in his programme so I just follow the same thing.
As far as your second post, no... you will not always be writing someone else's programs. You think that just because you can't do it, that we can't, as well?

As I said. Learn the syntax of the language.

http://www.cplusplus.com/doc/tutorial/
Uh... no Praxxtor, that's just you. Where to place semicolons, commas and stuff like that is determined by the grammar of the language. for example, a function call looks like this:
 
functionname(argument1[, argument2[, ... , argumentn]])
(the ['s and ]'s just indicate that the section is optional here, you don't actually write those in your code).

Simplified, there are 3 steps in programming:
1) Figure out what you want to.
2) Figure out what steps you need to do to achieve that.
3) Express the necessary steps in the programming language.

And yes, you can read as many tutorials as you want, you will never learn how to do step 1 and 2 - you either already have to have these skills, or acquire them through practice (most of the times people already have a basic understanding of what they want to do, but don't know yet how to break down problems so that they can easily be expressed as programs).

The only things tutorials are really good for is to show how a basic program looks like and how you can use parts of a program... once you got that much down, tutorials won't really help anymore. And of course you don't think "I do this because the tutorial said so", ideally you would understand what exactly you are doing, and can thus also easily tell why you are doing it.
Packetpirate, I didn't mean it like that, I meant me, but when you've dried your brain out with frustration my text comes out meaning the exact opposite heh. I am currently downloading the pdf tutorial onto my smartphone and will look through it where ever I am.

Okay, step 1 I've passed, step 2 sounds like googling projects and seeing how other people have done it or asking on a forum? Step 3 I am not so familiar with. Would reading through the c++ glossary of terms help, or is that a waste?
You don't need to remember any functions whatsoever. Learn the SYNTAX and keep a reference of the functions you need. IE: A cheat sheet.
Not remembering anything whatsoever is a kinda bad idea, I'm afraid that'd seriously affect your flow. Though you don't have to learn them like vocabulary lists either - stuff that you need often you'll remember anyways, and for stuff that you rarely need you got the references.
Try getting a good C++ book. Not only will a good book teach you the syntax and flow of the language, but most books will have excersises at the end of each chapter so that you can get a feel for how to write your own programs based on what you have just learned.
A tutorial is by definition not for teaching something new1; it is for taking something you already know and examining it thoroughly and exploring the implications and ramifications and conclusions (as an aside, most "tutorials" online are really no such thing - they're more isolated facts).

Before a tutorial is useful, knowledge is needed. Pick up a book, start reading, start learning.

To try to learn to code by copying other people's code without understanding anything is futile and frustrating. It's like trying to learn a foreign language by copying out a novel written in that language.

1. It shouldn't be. The meaning of the word has been diluted to the point where it's almost become synonymous with simply being told or shown something.
Last edited on
This is not easy to answer.

In order to become a decent programmer you MUST take on problems which confuse you and tackle them from many different angles. By this point in my life I am a competent programmer but by no means do I think that I am naturally suited to programming, I often struggle, just like you. I really belive that becoming a good programmer is all about battling through problems and learning your lessons the hard way, you must learn how to solve problems, and there's no tutorial for that.

Take on projects which challenge you, and if you feel that you honestly can't progress any further then this forum is a great place to ask for assistance.

Don't give up.
A tutorial is by definition not for teaching something new1; it is for taking something you already know and examining it thoroughly and exploring the implications and ramifications and conclusions (as an aside, most "tutorials" online are really no such thing - they're more isolated facts).
Where exactly did you get this definition?

1. A period of instruction given by a university or college tutor to an individual or very small group

2. An account or explanation of a subject, printed or on a computer screen, intended for private study
Where exactly did you get this definition?


History, mostly. It's becoming meaningless now, the term demeaned and cheapened. To my mind, the fact that you can now have a "tutorial" without a tutor renders it meaningless.

A period of instruction given by a university or college tutor to an individual or very small group


These would traditionally not be to cover new ground. New material was presented in larger groups; lectures. To cover new ground in small groups is horribly inefficient when it can be presented to large groups all at once. What cannot be done in large groups is what tutorials are for. The tutorial involves the tutor expanding on aspects of the material, chasing down the student's misunderstandings and exploring conclusions and deductions, illustrating the bare facts through careful application that leaves the student not only with the bare facts but the ability to apply them, to understand the subtleties and to use them in new situations. It's how it's still done in many universities, but the ongoing budget cuts are rending it less common.

An account or explanation of a subject, printed or on a computer screen, intended for private study


Where's the tutor? Where's the interaction? This definition includes reading a page of a book, and to say that's a tutorial is a travesty.

I do particularly despise (the majority of) programming "video tutorials". Someone records their screen while they type in some code and compile it. Takes longer than just reading the code, and adds nothing.
Last edited on
Tutorial has already been used to say "an introductionary guide to something" when I was a child, and I am fairly sure it wasn't new back then either.
It's not be impossible to have a written tutorial, so long as it managed to replicate the effects of a good tutor. I've yet to actually see one done well enough to honestly be a tutorial, but it's not impossible.

I'm not convinced on this one. To my mind, an "introductory guide" is an "introductory guide"; calling it a tutorial doesn't make it so. There's no back-and-forth, no exploration of the student's misunderstandings, no way to guide them carefully to an epiphany in which they suddenly stop regurgitating facts and actually start making the mental connections between what until that instant were disparate facts and have now become true understanding. The clue is in the name; tutorial.

The whoring of the term has taken a long time. Much as every other hack knocking together a shonky web-service they try to sell calls himself an entrepreneur with a startup, abusing the term to grandify something eventually renders it meaningless. Which is a real shame; an actual tutorial is exactly what the OP needs.
Last edited on
To my mind, an "introductory guide" is an "introductory guide"; calling it a tutorial doesn't make it so.
Well, that's your problem, really. The meaning of a word is determined first by how it is used, and second by its etymology. When you say "philosophy", do you mean "the study of general and fundamental problems", or do you use it as an umbrella term for all sciences? Is someone's "spirit" their "soul", or their "breath"?
Pages: 12