Shadow Blade
Morrowland Presents Apron Tutorials
game - design - multimedia - web - programming - tutorials - There are currently viewers visiting Apron Tutorials.
   
 
TECHNICAL
GRAPHICAL
SOUND
GAME
WEB
ARTICLE
TOOL
PROJECT
 
 NEWS

  news

  history


 TECHNICAL TUTORIALS

  opengl

  direct3d

  c/c++

  visual basic

  java

  c#


 WEB TUTORIALS

  html

  dhtml

  asp

  php


 IMAGE EDITING

  photoshop

  draw sketch


 3D MODELING

  3d studio


 PROJECTS

  shadow blade

  game environment

  virtual 3d guide

  billy blue flame


 DEMOS

  win32 api


 ARTICLES

  general

  opengl


 COMMUNITY

  about us

  credit

  contact












#include <stdio.h>
#include <iostream>	
using namespace std;					

// declare function 1 no argument
void myFunc_1();
// declare function 2 with an argument
void myFunc_2(int y);
// declare function 3 with an argument, returns an integer
int  myFunc_3(int z);	


int mySum1; // declare variables integer (global for this cpp file) 	
int mySum2; // when a variable is declared on the top, outside the functions
int x; // it means that all functions in this cpp-file have access to it.



int main()				
{	

	// Part I///////////////////////////////
	x = 5;
	myFunc_1();	// call function 1
	cout << mySum1 << endl; // display mySum1


	// Part II//////////////////////////////
	myFunc_2(5); // call function 2, pass in the value 5 as an argument.
	cout << mySum2 << endl; // display mySum2


	// Part III/////////////////////////////
	cout << myFunc_3(5) << endl; // display the returned value of function 3

	getchar(); // wait for a key to be pressed

	return 0;
}



void myFunc_1()	// define function 1
{
	mySum1 = x + 5;
}


void myFunc_2(int y) // define function 2 with an argument
{
	mySum2 = y + 3;
}


int myFunc_3(int z) // define function 3 with an argument, must return an integer
{

	return  z + 2;
}


/*
Learn to declare and define different functions.
and see how different functions handles the same type of task,
I have used different numbers so that you easier can tell them appart.



 Let us take a closer look at a function declaration:
----------------------------------------------------------------
 void myFunc_1();
----------------------------------------------------------------
 void		- means that the function is empty, it returnes no value

 myFunc_1	- the name of the function

 ()			- this means that there are no arguments

 ;			- end function declararion
----------------------------------------------------------------
 Decription:
 We declare our function to give the other functions access to it. 
----------------------------------------------------------------




 Let us take a closer look at a function definition:
----------------------------------------------------------------
 void myFunc_1()
 {
	mySum1 = x + 5;
 }
----------------------------------------------------------------
 void		- means that the function is empty, it returnes no value

 myFunc_1	- the name of the function

 {			- start function definition

 ()			- this means that there are no arguments

 mySum1 = x + 5;	- this is what our function does..

 }			- end function definition
----------------------------------------------------------------
 Decription:
 We must define what our function will do.
 This function takes the number 5, 
 and adds it with the value from the argument called x
 and stores the value in the variable mySum.
----------------------------------------------------------------




 Let us take a closer look at a function call:
----------------------------------------------------------------
 myFunc_1();
----------------------------------------------------------------
 myFunc_1	- the name of the function

 ()			- there is no argument passed in

 ;			- end the function call
----------------------------------------------------------------
 Decription:
 You must call your function in order to "put it to work".
----------------------------------------------------------------
*/



Download The Source Code! Download Visual C++ Source Code


I hope you found this c++ tutorial useful!

Don't forget to mention Apron Tutorials in your References!

Best Regards
Ronny André Reierstad

 LINKS

  morrowland home



 GAME DEVELOPEMENT

  nvidia

  gamedev

  polycount


 PROJECTS

  shadow blade

  game environment

  virtual 3d guide

  billy blue flame


 MATH AND PHYSICS

  mathworld

  physicsworld







PLEASE LINK TO


  All rights reserved Morrowland © 2011  
Ronny André Reierstad