Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 22nd, 2006, 2:25 PM   #1
peaceofpi
hi: for(;;) goto hi;
 
peaceofpi's Avatar
 
Join Date: Jun 2006
Posts: 123
Rep Power: 3 peaceofpi is on a distinguished road
Send a message via AIM to peaceofpi Send a message via MSN to peaceofpi
Are there any lessons for idiots?

I mean, I'm not an idiot. But, I just can't keep up with a lot of lessons online. The one at cplusplus.com? Lost me. Anything on Google? Lost me.

I downloaded "Wrox - C++ tutorial.chm" and it's been pretty good to me, but now I'm lost again at arrays. Eventually all lessons seem to assume you know a lot.

Is there anything besides a real life book (next plan) anyone can recommend to me, that teaches C++, while..."talking slow"?
__________________
How do you play Religious Roulette?
Stand around in a circle and blaspheme till someone gets struck by lightning.
peaceofpi is online now   Reply With Quote
Old Jun 22nd, 2006, 2:45 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I think you're letting things buffalo you that shouldn't. Probably because of that 'friend' of yours. Suppose you express one or two things that seem incomprehensible to you and let us take a shot at them. There is this about learning: something turns on the lightbulb above someone's head, but it takes a completely different slant to do the same thing for another.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 22nd, 2006, 2:56 PM   #3
peaceofpi
hi: for(;;) goto hi;
 
peaceofpi's Avatar
 
Join Date: Jun 2006
Posts: 123
Rep Power: 3 peaceofpi is on a distinguished road
Send a message via AIM to peaceofpi Send a message via MSN to peaceofpi
This problem existed before the whole Assembly debate, I've had problems getting very far in programming languages since I started.

So far, I've got most of the "basics" down. I can do if, else (if), while, all that stuff. This "for" thing has me a little intimidated, but I might've just not read enough into it.

Like I said, arrays have me confused as well. I can declare an array fine, and do some small things with the data inside; I guess I just don't know why I should use it. I also don't get why char variableName[]; would be more effective than string variableName;, but I'm still new.

I'm also working on figuring out functions and stuff, since I think it would probably make for cleaner code in large scripts. (One thing I'd like to learn, if possible, is defining functions in one file and being able to use them in your main one)

Again, a lot of the tutorials confuse me. As if they're not complicated enough, none of them go in the exact same order. So I might have a small grasp on one subject, until it gets too complicated, then move on to "chapter 3" in another tutorial where they teach something else. This causes me to do less studying than I should, since I want to learn.
__________________
How do you play Religious Roulette?
Stand around in a circle and blaspheme till someone gets struck by lightning.
peaceofpi is online now   Reply With Quote
Old Jun 22nd, 2006, 3:11 PM   #4
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 655
Rep Power: 4 Jessehk is on a distinguished road
Quote:
Originally Posted by peaceofpi
I also don't get why char variableName[]; would be more effective than string variableName;, but I'm still new.
It wouldn't, but that is only because arrays of chars were replaced by std::strings.

Arrays are useful when you want to keep track of a bunch of similar values. In many cases, std::vector in C++ can replace them, though there are still some valid uses. Here is an example:

#include <iostream>

int main() {
    // Declare an array to hold 5 scores, all of type int.
    int scores[5];

    // I'm writing this in a format that is easier to comment
    // usually 'for' loops would be written all in one line.
    //
    for(int x = 0;  //Set 'x' to be 0. It is only set once.
        x < 5;      //Iterate while x is less then 5.
        x++)        //At every iteration, increase the value of 'x' by 1
    {
        std::cout <<  "Enter score: ";

        //Get input for each successive element in the array
        std::cin >> scores[x];
    }

    std::cout << "You entered the following scores:\n";

    //Display the contents of the array.
    for(int x = 0; x < 5; x++)
        std::cout << scores[x] << std::endl;
}
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Jun 22nd, 2006, 3:15 PM   #5
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Post

I'll just explain a for loop for you.

In a lot of langauges you can find for loops. As you say you understand while loops I can easily explain how to use them.


Here is an example of a for loop:
for(int x = 1; x < 11; x++;){
   std::cout<< x <<std::endl;
}

This code would write the numbers 1 to 10.


Firstly you make your new variable:
for(int x = 1; x < 11; x++){
   std::cout<< x <<std::endl;
}

This variable is named x in this loop and it will last until the for loop ends, then it will be discarded.

Next, you make a condition, here we have "x < 11" this basically means: While x is less than 11, continue the loop.

Then you state what will happen to the variable after each loop, in this case I use x++ which increments the value by one.

So this for loop would look like this if it was a while loop:
int x = 1;
while (x < 11){ 
   std::cout<< x <<std::endl; 
   x++; /* increment x by one */
}

For loops can differ a lot from that small example but this is the general idea. You can do a lot of other things like leaving parameters out.

:banana:
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Jun 22nd, 2006, 3:26 PM   #6
peaceofpi
hi: for(;;) goto hi;
 
peaceofpi's Avatar
 
Join Date: Jun 2006
Posts: 123
Rep Power: 3 peaceofpi is on a distinguished road
Send a message via AIM to peaceofpi Send a message via MSN to peaceofpi
Aha. So a "for" is (basically) initializing a variable combined with a while loop of some sort.

I'm creating my own examples (by memory, without looking at what you gave me) to see if I can get it right on my own. Hitting some speed bumps, but the whole for thing is clear now.

I guess the next thing I need to tackle is pointers, which really threw me off.
__________________
How do you play Religious Roulette?
Stand around in a circle and blaspheme till someone gets struck by lightning.
peaceofpi is online now   Reply With Quote
Old Jun 22nd, 2006, 3:55 PM   #7
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 773
Rep Power: 3 Jimbo is on a distinguished road
A for loops works like this (one line pseudo-code definition):
for(Initialization; Condition; Update)
{
  // ...
}
The first part you initialize a variable for using in the loop. This is usually an array index, iterator, or something similar (not always the case though). Then you have a conditional statement, determining whether to continue the loop. Then you have an update segment to update anything for the next iteration. A for loop can also be written as:
Initialization;
while(Condition)
{
  // ...
  Update;
}
Remember though, that any variables decared in the Initialization of a for loop will only exist in the scope of that loop.
Jimbo is offline   Reply With Quote
Old Jun 22nd, 2006, 4:04 PM   #8
LOI Kratong
Professional Programmer
 
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4 LOI Kratong is on a distinguished road
peaceofpi, I wouldn't even try and touch pointers until you at least have a fairly good grasp of the rest of the basic stuff you've mentioned, they throw a lot of people off at first, try to tackle them with a clear head, without wondering why the heck the example is doing that thing with that arrayjamawhatjimacallit!

But in all seriousness I think people will agree with me on that, get a good foundation, then expand!
__________________
www.heldtogether.co.uk
LOI Kratong is offline   Reply With Quote
Old Jun 22nd, 2006, 4:06 PM   #9
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
But when you do look at pointers, head over to http://daweidesigns.com and read up about pointers there.
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Jun 22nd, 2006, 4:41 PM   #10
Namingishard
Newbie
 
Join Date: Feb 2006
Location: TX
Posts: 23
Rep Power: 0 Namingishard is on a distinguished road
Send a message via AIM to Namingishard Send a message via MSN to Namingishard
When your stuck on something, dont just skip it and keep going, and going, stop, backup and read it again, almost always works for me.
Its easy to say...oh that doesn't look to importent and skip it "For now",
but thats what gets you in trouble >_<, i did alot of that when i first started,
Then i got smart and just read everything multiple times.
Anyways good luck =P
Namingishard is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:24 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC