how can I learn to write functions

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read how to get help
Post Reply
kaykav
Level 3
Level 3
Posts: 148
Joined: Tue Jan 06, 2009 12:09 am
Location: crossville tn

how can I learn to write functions

Post by kaykav »

HI
I'm at my last resort. Where can I learn to write functions in programming? I have been reading and trying to understand how to write a function for three or four months now,and I just don't seem to get it.
I keep going over the definition without fully understanding what it is, or does. I'm totally confused and almost frustrated. I have been thru many tutorials,articles,and explanations to no avail. Anyway ,
I was hoping, asking you (forum), for advice. Ultimately learning C++ or Python. Thank you...
User avatar
DataMan
Level 6
Level 6
Posts: 1234
Joined: Thu Dec 04, 2008 6:47 am
Location: Carmel, Midwest USA at /var/www
Contact:

Re: how can I learn to write functions

Post by DataMan »

I can help you with PHP, but that was not on your language list... :)

You may want to

1. Search at:
2. If #1 fails, do a posting on:

http://ubuntuforums.org/forumdisplay.php?f=310

The scope of these boards is pretty much hard core programming.

-DataMan
Linux'd since 2005 Linux ID 422356 Ubuntu ID 15015
kaykav
Level 3
Level 3
Posts: 148
Joined: Tue Jan 06, 2009 12:09 am
Location: crossville tn

Re: how can I learn to write functions

Post by kaykav »

Dataman
ok I'll give your advice a try...I'll get back to you....thanks
User avatar
Aging Technogeek
Level 13
Level 13
Posts: 4578
Joined: Sun Jan 11, 2009 9:54 am
Location: Right about here

Re: how can I learn to write functions

Post by Aging Technogeek »

I am finding this a good source for learning the basics of Python

http://learnpythonthehardway.org/index

Do not be afraid of the title, what it really means is that you will learn Python the old-fashioned way. It starts with very simple exercises and each lesson builds on the previous one. It does not try to be a text for advanced programmers. It is a Python primer equivalent to a beginner's reader. When you have finished the book, you will have the basic knowledge and grounding to go on to advanced Python programming.
Registered Linux User 483387
kaykav
Level 3
Level 3
Posts: 148
Joined: Tue Jan 06, 2009 12:09 am
Location: crossville tn

Re: how can I learn to write functions

Post by kaykav »

aging technogeek,
Sorry It ook so long to reply. I tried most of 'python the hard way'. It's pretty good. I'll just keep doing it over and over. Thanks...
MrCleanWithHair
Level 1
Level 1
Posts: 15
Joined: Sun Mar 07, 2010 11:51 pm

Re: how can I learn to write functions

Post by MrCleanWithHair »

Code: Select all

// function example
#include <iostream>
using namespace std;

int addition (int a, int b)
{
  int r;
  r=a+b;
  return (r);
}

int main ()
{
  int z;
  z = addition (5,3);
  cout << "The result is " << z;
  return 0;
}
In this example addition is the name of the function.

(int a, int b) are parameters that are passed to the function.

everything inside the { } is what the function does.

the last line in the function is the value the function returns, in this case an integer.

That's really all there is to functions, at least simple ones.

http://www.cplusplus.com/doc/tutorial/functions/
Post Reply

Return to “Other topics”