Has this happened to you :(

closed account (iAk3T05o)
I've been learning C++ for a while now. My problem is i am having problems understanding anything after the "Switch" topic in the pdf tutorial of this site. I know how to use everything before the switch topic but i can't seem to understand anything past that. :(

Maybe i need a time-out. I guess it's what authors experience as writers block (idk)

I don't understand functions, arrays.
Has it happened to you. :(
Actually I find pointers really confusing for beginner. It's something that required me to approach it few times before I got it. Now It's kinda of natural how it works, yet I'm sure they will surprise me few times :P

If you don't understand switch(case) statement, first try to look for other tutorials - if this one doesn't fit you, maybe other will.
If you still don't get it, try to write a code and see how it behaves. You can learn really much by simply testing code.

And afterwards, if it's still unclear - ask :)

Good luck!
closed account (iAk3T05o)
I'm at the point where i write code that does what i want, but don't even understand the code i'm writing. :(


@Matthew: I haven't even passed arrays much less learning pointers.
Last edited on
If you do not understand your code, then it's bad. You should have at least slight knowledge what's going on. If you are not learning deeply enough, this may be the case(pun not intended) of your problems.
closed account (iAk3T05o)
I am learning deeply, mostly for loops code i don't understand. (for (blah)) doesn't seem right to me so it takes a while to understand it even though i understand the other parts. Just downloaded the c++ programming language 4th edition pdf. i hope learning from a new pdf will help the matter.
closed account (iAk3T05o)
I also found the exercise pdf. Looking good
Well I personally was learning these basic things like if statements and loops for quite a year (because I learned them in school), and I noticed that everything that comes after that is a bit harder. But functions themselves are kinda easy to understand (works similar to mathematical functions) and arrays are hard to understand but easy to use.
So as I said I've been wasting my time whole year on this kind of stuff you said you understood and everything that came afterwards was easy for me because I already had clear knowledge what is C++ and how does it work.
My suggestions? Well, just try to understand what you're doing and always, always practice, try to type the code without any help, give yourself tasks and so on. Only by trial and error you will learn something. Also, what I can say is that information in this site isn't given the best way and there are LOTS of information, so don't rush, try to understand one part even if it takes a day or two.
Last edited on
Both at the beginning, and later, you sometimes have to think for a while before you get what's going on in the code. :)
closed account (iAk3T05o)
@uzferry: a year :o learning loops and if/else statements. Wow, there is no way i would be able to do that.
And functions aren't easy (for me).
Hope i get over this soon (got sooooo many ideas and that's my main motivation).
Last edited on
http://www.tutorialspoint.com/cplusplus/cpp_loop_types.htm

This site helped me with loops a bunch, see if it helps you.
closed account (iAk3T05o)
Yeah, i have the tutorialspoint cpp pdf. Haven't started with it yet. Maybe i should.
The easy way to think of switch statements is alot like glorified if/else statements. I personally agree with MatthewRock, I found pointers and references more confusing, but I have a background with basic which used similar loops so I had no problem with those. Imagine instead of using if/else to decide how to respond to a variable being equal to 1,2, or 3, we use a switch statement. If we did, it would look something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    
int c=7;
    switch (c)
    {
case 1:
    cout<<"c is 1";
    break;
case 2:
    cout<<"c is 2";
    break;
case 3:
    cout<<"c is 3";
    break;
default:
    cout<<"c is not 1,2, or 3";
    break;
    }

It's a real simple example, but it's the exact same as this:
1
2
3
4
5
6
7
8
9
int c=7;
if (c==1)
cout<<"c is 1";
else if (c==2)
cout<<"c is 2";
else if (c==3)
cout<<"c is 3";
else
cout<<"c is not 1,2, or 3";

The reason for all those break statements is that they define the end of each case, or if statement, if you prefer. If you were to leave out the break on line 10, for instance, it would say c is 2 followed by c is 3. This can be annoying if you forget your break statement, but it can be useful when used strategically. For instance, if c is 1, you can have it do all things, if c is 2 it can do all things except the first, etc. But in this case, both code results in the same thing. I know that sometimes it is difficult to wrap your head around a new concept, and I think presenting it as an alternative to something familiar helps so you can see the concept at work. If only some of the learning materials took a similar approach, I would have a better understanding of pointers, references, and vectors, so I share your frustration. We all hit obstacles and snags in the learning experience.

Try not to get too discouraged; sometimes the right example or code snippet comes along and suddenly you understand how a concept works, although you may be more comfortable using it a certain way, at first. It's all part of the learning experience. If you find for loops particular confusing, stick with while loops where you can control the loop directly, it may be different, but has the same ability as a for loop, it's only that the counter is not "built in". Don't be afraid to try other people's code with loops in them, and changing the values to see how it affects program behavior. Try to stick with simple stuff, like outputting a few stars to each line, until you get the hang of it. If you start another thread about loops, or post in another loop related thread, I'm sure you can get plenty of guidance on the topic, and the same can be said for functions and arrays. I myself had trouble with arrays, at first, but then I had a major breakthrough and managed to create a tic tac toe game using one dimensional arrays, and from there changed it to a 2 dimensional array and then created Connect Four. But we all experience confusion when first encountering unfamiliar concepts; try not to let it hinder you too much, the key is in finding simple examples that aid in understanding how something works.
Last edited on
Topic archived. No new replies allowed.