Jump to content


Photo
* * * * - 1 votes

c++ learning and comprehension


  • This topic is locked This topic is locked
80 replies to this topic

#41 rainwater_stillicide

rainwater_stillicide

    SUP3R 31337 P1MP

  • Agents of the Revolution
  • 282 posts
  • Location:Scotland

Posted 10 March 2007 - 03:06 AM

the main section calls the function with the argument 5 so the function computers:
1 + 2 + 3 + 4 + 5
which equals 15.

#42 Avatar/Oroborus

Avatar/Oroborus

    elite

  • Members
  • 109 posts
  • Location:san jose, CA

Posted 10 March 2007 - 04:46 AM

ok thank you for that cause i figured out what it did but just not how it was added or the result

#43 PurpleJesus

PurpleJesus

    Dangerous free thinker

  • Members
  • 1,578 posts
  • Gender:Male
  • Location:800

Posted 10 March 2007 - 11:02 AM

Yeah, I saw that it was adding up the sum of individual digits ... but I couldn't figure out what the testing of max against a negative number was all about... That part threw me for a moment.

//edit

Could use a formula instead... print n, ((n+1)*n)/2

seems to work..

Edited by PurpleJesus, 10 March 2007 - 01:10 PM.


#44 rainwater_stillicide

rainwater_stillicide

    SUP3R 31337 P1MP

  • Agents of the Revolution
  • 282 posts
  • Location:Scotland

Posted 10 March 2007 - 02:00 PM

Yeah, I saw that it was adding up the sum of individual digits ... but I couldn't figure out what the testing of max against a negative number was all about... That part threw me for a moment.

//edit

Could use a formula instead... print n, ((n+1)*n)/2

seems to work..


yes, you can (and in 'real life' probably should), but the point was for spongebob crazypants up there to get practice with functions and loops and whatnot.

Edited by rainwater_stillicide, 10 March 2007 - 02:01 PM.


#45 Avatar/Oroborus

Avatar/Oroborus

    elite

  • Members
  • 109 posts
  • Location:san jose, CA

Posted 10 March 2007 - 08:41 PM

Hi im spongebob crazypants, but that pseudo code confused the hell out of me about functions. So could someone else explain it to me a lil better.


also how is it that script kiddies get anything done i've tried hacking while others products , like brutus, shadow scan, nmap (nmap is a awesome port scanner), metasploit but i never get anything done could someone explain to me more about ports and ips or if they don't have the time to point me to a good tcp/ip document thanks

#46 tehbizz

tehbizz

    Progenitor of noob slaying

  • Members
  • 2,039 posts
  • Gender:Male

Posted 10 March 2007 - 10:00 PM

Hi im spongebob crazypants, but that pseudo code confused the hell out of me about functions. So could someone else explain it to me a lil better.


also how is it that script kiddies get anything done i've tried hacking while others products , like brutus, shadow scan, nmap (nmap is a awesome port scanner), metasploit but i never get anything done could someone explain to me more about ports and ips or if they don't have the time to point me to a good tcp/ip document thanks


Read your 15 C++ books, I guarantee they tell you exactly how functions work.

#47 Ohm

Ohm

    I could have written a book with all of these posts

  • Members
  • 3,209 posts
  • Gender:Male
  • Location:Maine, USA

Posted 10 March 2007 - 10:15 PM

Read your 15 C++ books, I guarantee they tell you exactly how functions work.


You don't let up, do you?

What we're all trying to get at is: read about them yourself. A function is not a difficult concept. You should have moved past functions within your first hour or two of learning. If you don't have the ambition to learn something so simple for yourself, no one is going to waste their time helping you. Why should they, you're just going to turn around and ask another question you'd know the answer to if you read your 15 (sorry, couldn't help myself) C++ books.

Edited by Ohm, 10 March 2007 - 10:16 PM.


#48 Avatar/Oroborus

Avatar/Oroborus

    elite

  • Members
  • 109 posts
  • Location:san jose, CA

Posted 10 March 2007 - 10:44 PM

yes but apparently i dont get the concept of functions that well so im asking for a simpler explanation, then from the boks i read who are wrote for programmers by programmers and all beginner programming books focus more on abstract programming then functions. they give you a gay explanation and a even dumper example of adding 2+2 the returning the value but i get lost in translation some where and need help stop with the you need to read the books cause i think it would be muchg easier for you to explain this then write a paragraph on why i should read or what i should be doing

#49 Ohm

Ohm

    I could have written a book with all of these posts

  • Members
  • 3,209 posts
  • Gender:Male
  • Location:Maine, USA

Posted 10 March 2007 - 10:59 PM

Trust me, your "beginner programming books" cover functions. Why not read them? I'm not aware of any professional writers here on the board, so I'm sure functions explained better in the books. Try reading them.

#50 Avatar/Oroborus

Avatar/Oroborus

    elite

  • Members
  • 109 posts
  • Location:san jose, CA

Posted 10 March 2007 - 11:09 PM

as you saw from my last entry i did read them, i can't unstand the concept that they are trying to pass i know a function is like a global variable i can be called at anytime but i can't understand the concept of them in general and i know im hard to understand but im not a englisch major im psychology and philosophy im trying to move into computer science but i want to get a head start on it

#51 deadc0de

deadc0de

    SUP3R 31337 P1MP

  • Members
  • 272 posts
  • Location:ring0

Posted 11 March 2007 - 12:32 AM

how does everyone here or on rohitab.com generate so much unique coe and know so much about the c++ lang. when all of the examples in ebooks or tutorials are all the damn same i/o or string handling you talk about win sock and api hooks and all of this stuff and when beginners ask how do you do it alot of the time google well im asking how do you find this info out is there some magical thing, i have some source code and it is amazing but i can't understand how exactly it works i know what each part basically does so all im asking is how do you find out about more practical programming



You don't learn to be a good coder. Good coders are good coders. Basically they do it because their imagination (and skill) is essentially limitless. Your not gonna go anywhere, or learn anything through mindless droning through ebooks, tuts, and white papers. You have to understand what they are doing and take it slow enough so you understand it's uses. I help a kid weekly on C++ and he sounds exactly like you. What I did to learn was this. I went through the book and typed out all the examples. I did the tests at the end of the chapter and then read about the different things it's used for on the internet. Then when I finished a chapter I made a program using the knowledge from the previous sections and the current chapter all off my own ideas. That's what I believe taught me to be a practical programmer. It sounds like you think you know what you are doing, but you have no clue how to implement it in the real world. Maybe take on a few coding projects to ease your way into more practical programming through other's ideas.


It's all your imagination my friend and if your a hacker, you probably have one hell of one.

Edited by deadc0de, 11 March 2007 - 12:34 AM.


#52 tehbizz

tehbizz

    Progenitor of noob slaying

  • Members
  • 2,039 posts
  • Gender:Male

Posted 11 March 2007 - 12:48 AM

Read your 15 C++ books, I guarantee they tell you exactly how functions work.


You don't let up, do you?

What we're all trying to get at is: read about them yourself. A function is not a difficult concept. You should have moved past functions within your first hour or two of learning. If you don't have the ambition to learn something so simple for yourself, no one is going to waste their time helping you. Why should they, you're just going to turn around and ask another question you'd know the answer to if you read your 15 (sorry, couldn't help myself) C++ books.


Nope, there's no point in giving up.

While you "read" 15 books on C++, you seem to lack an extremely basic understanding of it so I'm not wondering if actually read them, I'm wondering if you only read the parts that showed code and tried to learn by only reading that.

Honestly, understanding functions is simple. As Ohm said, you should have gotten past them in the first hour or two of reading and gained a working knowledge of them. But apparently, out of all 15 books, they're written so complex only experienced programmers can read them and the beginners books are "too" dumb (hint: there is never TOO dumb) for you to bother with.

Go back and read or admit that you really don't understand any of it and politely (read: without your ego) ask for help.

#53 Avatar/Oroborus

Avatar/Oroborus

    elite

  • Members
  • 109 posts
  • Location:san jose, CA

Posted 11 March 2007 - 01:39 AM

well im not trying to seem like i have a big ego but i know the way i learn and no i read them i don't just look at the preety pictures of code i do lack a basic comprehension of functions and everyting the guy who replied before you helped more then any one else he understood the title of this discussion and that is how everyone else learnt and what helped them with learning and comprehension of the different data types and features of c++ i don't have to stroke my ego online im asking for simple help with by finding out what helped you. i read the books over and over again the more i read the less i understand

#54 dalejrrocks

dalejrrocks

    SUPR3M3 31337 Mack Daddy P1MP

  • Members
  • 472 posts
  • Location:Alabama

Posted 11 March 2007 - 03:21 AM

well im not trying to seem like i have a big ego but i know the way i learn and no i read them i don't just look at the preety pictures of code i do lack a basic comprehension of functions and everyting the guy who replied before you helped more then any one else he understood the title of this discussion and that is how everyone else learnt and what helped them with learning and comprehension of the different data types and features of c++ i don't have to stroke my ego online im asking for simple help with by finding out what helped you. i read the books over and over again the more i read the less i understand


Is it me or are the last few posts essentially the same thing where he whines and keeps pushing for someone to explain the basic concept of a function?

Have you tried writing a simple function and then trying to use it in different ways so maybe you would learn visually and from practical experience? That helps me sometimes.
Maybe something like : (Excuse my java)

int Add(num1, num2) {
return num1+num2;
}

and then using that function as a part of a larger code?
Maybe you could get two numbers, execute the function, and then print out the value of the function?
That would be a simple program.. I really don't know how to explain it any simpler.

#55 Avatar/Oroborus

Avatar/Oroborus

    elite

  • Members
  • 109 posts
  • Location:san jose, CA

Posted 11 March 2007 - 03:42 AM

like this
int add(num1, num2){
	  return num1 + num2;
}
main()
{
   int num1, num2;
   cin >> num1;
   cin >> num2
   add();
   cout << add();
   return 0;
}

hold on i m going to run this real quick

#56 Avatar/Oroborus

Avatar/Oroborus

    elite

  • Members
  • 109 posts
  • Location:san jose, CA

Posted 11 March 2007 - 03:55 AM

ok now im more confused

#57 rainwater_stillicide

rainwater_stillicide

    SUP3R 31337 P1MP

  • Agents of the Revolution
  • 282 posts
  • Location:Scotland

Posted 11 March 2007 - 04:40 AM

#include <iostream> //1

using namespace::std; //1

int add(int num1, int num2){ // 4
	  return num1 + num2;
}

main()
{
   int num1, num2;
   cin >> num1;
   cin >> num2; //2
   cout << add(num1, num2); //3
   return 0;
}

This is a working version of the code you posted.
The changes have been numbered in the comments:

1. didn't import iostream so the program couldn't use cin or cout

2. no semi-colon on the line: cin >> num2

3. called add with no arguments.
The function is delcared with two arguments: int add(int num1, int num2)
so when you call it you need to supply two ints in the brackets: add(3, 4) or add(num1, num2)

4. no types given for arguments in function delceration (you need to write the types of the input that the function)
When a function is declared it needs to know what type of arguments to expect:
int add(num1, num2) doesn't tell it what num1 and num2 are, they might be ints but they could just as easily be characters or anything else.

you need to write:
int add(int num1, int num2) so that it knows to expect ints.

#58 Avatar/Oroborus

Avatar/Oroborus

    elite

  • Members
  • 109 posts
  • Location:san jose, CA

Posted 11 March 2007 - 04:58 AM

ok thank you very much and when i ran it i fixed the semicolon problem and i re read the code and this helps uber mucho thank you so much

#59 Avatar/Oroborus

Avatar/Oroborus

    elite

  • Members
  • 109 posts
  • Location:san jose, CA

Posted 11 March 2007 - 05:02 AM

i have another question too i know what arguments are in the above program but i sometimes hear of command line arguments and other things where there is just one funstion like hold on

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	system("PAUSE");
	return EXIT_SUCCESS;
}

what are these arguments for
int main(int argc, char *argv[])


#60 Ohm

Ohm

    I could have written a book with all of these posts

  • Members
  • 3,209 posts
  • Gender:Male
  • Location:Maine, USA

Posted 11 March 2007 - 09:48 AM

ok thank you very much and when i ran it i fixed the semicolon problem and i re read the code and this helps uber mucho thank you so much


Ironically, after you've finally convinced someone to give you an example of a function, it looks exactly like (surprise!) examples you might find in your 15 C++ books. I don't mean to drone on and on here, but you did exactly what I said you would. Someone finally answered your question that could have easily been answered by reading your books, and then you turn around and ask another such question. The argc and argv variables are covered in your 15 C++ books.




BinRev is hosted by the great people at Lunarpages!