New here

hello all,over the past several years from time to time I dig into the basics of programming.i understand bits and pieces,but im just not grasping it like I want.when I sit down and look at actual code thats been written by someone else and it just seems like jibberish.id just like to be able know what im looking at.i know what a program does,but what do all the functions do,how do I know when to use them.if someone wishes to point me in a good direction that would be greatly appreciated.lol I have a programming book for dummies,they arent very descriptive though,thanks in advance
Read the tutorial available on this website in documentation
hey welcome to the forum, I think the main problem you are having is due to the lack of understanding of program design.

Usually when you buy a book on programming they do not discuss how to actually design programs, they teach you syntax of a specific programming language.

In program design, basically you have 3 basic control structures which will allow you to create any kind of program you want, they are:

1. sequential
2. selection
3. iteration

the sequential control structure is usually the default, when you create a program it executes each statement by sequence.

the selection control structure is used when you want to do different things depending on different values, for example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string password = "";   // create a string to hold our password
    
    cout << "password: ";
    cin >> password;

    // selection control structure
    // the program does something different depending on the conditions
    if(password == "mypass")
    {
         cout << "access granted\n";  // it only executes this part if the condition was true
    }
    else
    {
        cout << "access denied\n";    // it will execute this part if the condition was false
    }

    return 0;
}


Anyway, the selection control structure allows your program to do different things or execute different statements depending on when certain values are achieved. if statements and switch statements would fall under this category.

Next is the iteration control structure, you use iteration control structures when you need to do something repeatedly, usually you can use these when there is a simple predefined pattern you want to achieve which you need to do repeatedly.

for example if you want to print out something 5 times:

1
2
3
4
5
// iteration control structure
for(int i = 0; i < 5; i++)
{
    cout << "hello world\n";     // print out hello world 5 times
}


or if you want to print out even numbers from 0 to 100

1
2
3
4
5
// iteration control structure
for(int i = 0; i < 100; i += 2)
{
     cout << i << "\n";
}


you can also use it to keep your program running until someone tries to exit.

1
2
3
4
5
6
7
8
bool exit = false;

// iteration control structure
while(!exit)
{
     // do whatever you want your program to do here
     // if the user is trying to exit, set the exit value as true
}


Anyways, for, while, do-while and all kind of looping mechanisms would fall under the iteration category.

Anyways these are just some examples, so those are the basic elements all programs have. Then all you have to do is to learn how to combine those to create what you want to do. You can combine something to keep iterating then select what it's going to do like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// iteration control structure
while(condition)
{
     // selection control structure
     if(some condition is true)
     {
         // do something
     }
     else if ( some other condition is true)
     {
         // do something else
     }
     else
     {
          // none of the conditions are true
          // do something
     }
}



or you can select something, then what it does is iterates to create the result.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// selection control structure
if(condition)
{
      // iteration control structure
      while( some condition is true)
      {
           // do something
      }
}
else if(another condition)
{
      // iteration control structure
      while( some condition is true)
      {
           // do something
      }
}
else
{
      // do something
}


Once you know how to combine those 3, then you can make any kind of program. All the rest of the syntax is just for improving the design of your program. Like classes, templates, functions, etc.

So if you really want to learn how to program I think you need to focus on those 3 things first, and learn how to combine them in different ways. Once you master those, then you can move on to improving your programs by using templates, classes, functions, and etc. I hope that helps point you in the right direction you were looking for. =)
Last edited on
Good to know there are different structures of programming.my biggest concern is what symbols mean in the programming world.like for example under the selection control example you provided you put quotes next to the semicolon on the "cout << password" line but not the "cin" line.anywho my main focus is game programming.thanks for the examples
before you use a string you have to use the string header file
Not sure what a string is.sorry not trying to be difficult.im just a newbie lol
its okay were all there at one point. Do you know what the var (variable) type char (character) is? It can only hold one letter. If you want more than a letter though include the header file string and instead of char write string
Ive heard of var and char.it seems as though I have alot to learn.
oh, you need to learn about variables then. You can't use selection or iteration control structures without them.

before you use a string you have to use the string header file


whoops, forgot about that lolz, edited
Last edited on
No worries,like I said im just looking for a good place to start,ive never written a program yet.currently the only programs I deal with are related to machining
currently the only programs I deal with are related to machining


aren't those programs a lot harder though? I thought those are closer to low level programming like assembly and stuff. :P
like for example under the selection control example you provided you put quotes next to the semicolon on the "cout << password" line but not the "cin" line.


cout, means console out. This will print to the console what ever is in between the "double qutoes", within reason.

Whereas cin, means console in. You will be getting input, to the console and storing the input, into the variable 'password'.

1
2
3
4
5
//print          string;
   cout   <<  "Password: "

//get input      strore in variable
    cin     >>      password


A string is a sequence of characters, eg. "Hello, world!".
A string may include letters, digits, and various special characters.
Topic archived. No new replies allowed.