Logic

• 05-22-2006
LordBronz
Logic
In C++, logic plays an enourmous role. I feel I have no logic whatsoever. I know a good bit of code but I can not make a program whatsoever. Did anyone else have this problem? How could I overcome this problem of logic?

Help will be greatly appreciated, thanks ahead.
• 05-22-2006
jmd15
No, I never had that problem but the only way around it seems to be going through it. You NEED logic to code and to gain the skills neccessary to be logical you have to practice using logic. Through the use and practice of logical activities you can gain the neccessary skills. So my advice in a nutshell, practice.
• 05-22-2006
KyussWren
The Rules

Program that for a 2 user game.
Then expand to N users.

Also, Wikipedia has some interesting articles on logic, and the offshoots of logic.
• 05-22-2006
LordBronz
Oh haha, really good man, you really got me. How about posting something useful maybe?
• 05-22-2006
KyussWren
Its actually a really simple program for 2 users man.
Just have each of those with an array that has the selection at 0, all the stuff that beats it as a positive, all the stuff that it beats as negative. then check.
• 05-22-2006
Sebastiani
the basic principles are found in the rules of boolean algebra and the operation of logic gates. learning how to solve/simplify logic equations using DeMorgan's laws and Kernaugh maps is a good idea, too.
• 05-23-2006
DougDbug
How about an example of what you are having trouble with? Programming logic isn't really that hard.

But, if you are are new to programming (in the first few weeks of a programming class, for example) it can be tough, because you have to learn what programming is all about, how programs run/work, as well as learning C++ and how to use your compiler. I remember being really lost in my first programming class. It gets easier with your 3rd or 4th programming language. :D (Except for C++... Most of us will never learn C++ completely... There's a lot to it... You can't even find a book that covers the whole language!*)

Quote:

I know a good bit of code but I can not make a program whatsoever.
You need to start-out by knowing what the program is supposed to do. Then, you can make a list, outline, or flowchart of how to get "from point A to point B."

If you are given a homework assignment, most of that "outline" will be given (or hinted at) in the assignment. If not, there will be some good hints in the lecture/reading.

It's important to know the kinds of things you can do in a program:

Loop:
Do stuff over & over.
Make decisions based on conditions: if-statements & switch-case statements.
Make calculations and comparisons.
Input / output: Keyboard, display, disk, printer, etc.

I usually make an outline, and I write it in the form of comments... starting each line with "//". Then, I start filling-in the actual code, and I'll edit the comments as I go-along so that the final comments to make them more "comment-like", and describe what the program is actually doing, rather than what it's supposed to do.

* You can get a printed copy of the complete C++ Language Standard (the language “specification”).