collapse collapse

* Who's Online

  • Dot Guests: 93
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11163
  • stats Total Topics: 1699
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 248

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - GodLord

Pages: [1] 2
C++ / Using variables from header files?
« on: February 17, 2011, 08:04:15 pm »
Code: C++
  1. #ifndef
  2. #define HEADER_H
  3. class myClass{
  4. public:
  5.       int j;
  6. };
  7. #endif
Code: C++
  1. #include <iostream>
  2. #include "test.h"
  3. int main(int argc,  _TCHAR* argv[])
  4. {
  5.       cout << test::j << endl;
  6.       return (0);
  7. }

What is the problem with this? Also what is the difference between:
Code: C++
  1. #include <test.h>
Code: C++
  1. #include "test.h>

Physics / Magnitude of a Net Charge within a closed surface
« on: February 13, 2011, 08:59:29 pm »
1. The problem statement, all variables and given/known data

A closed surface with dimensions a = b =
0.254 m and c = 0.4064 m is located as in
the figure. The electric field throughout the
region is nonuniform and given by ~E = (α +
β x^2)ı where x is in meters, α = 4 N/C, and
β = 6 N/(C m2).

Picture of object attached.

What is the magnitude of the net charge
enclosed by the surface?
Answer in units of C.

2. Relevant equations

Gauss's Law: flux = integral(E dA) = Q/permittivity constant

permittivity constant(epsilon naught) = 8.85E-12

3. The attempt at a solution

I know that the object doesn't not have any flux through any of the sides except the left and right sides(those parallel to the electric field). So I thought to find net flux and multiply that by the permittivity constant and find the net charge enclosed.

Flux1 = (α +β (a+c)^2)*(a*b) = electric field * area of the side(right)
Flux2 = (α +β (a)^2) * (a*b) = Electric field * area of the other side(left)

Flux1 + Flux2 = 0.709925351759
Therefore I multiply by epsilon naught:
net flux * epsilon naught = 6.28283939307E-12

However this is wrong, I believe I am messing up because of the weird way they are giving the electric field as, or possibly my entire calculations or process?

Java / Event Handlers -- Java
« on: April 25, 2010, 01:26:53 am »
In the last tutorial I showed how to make a basic GUI system. It wasn't anything great but I will use that same code because it has already been explained.

To start off event handlers are basically listeners which wait for something to happen in your GUI then do something else!

The event handlers which buttons use is called the ActionListener. You must implement this class into your's and then define it's only abstract method called:


The best way is to learn by example:
Code: Java
  1. /*
  2. //
  3. //@author: GodLord
  4. //
  5. */
  7. import javax.swing.*;//all required to use the correct classes to create a
  8. import java.awt.*;//healthy GUI system
  9. import java.util.*;
  10. import java.awt.event.*;//imported to allow events!!!!!!
  13. //ADDED!!!!!!!!!!!!!!!!!!!!!!! implementing ActionListener below!
  15. public class mainGUI extends JFrame implements ActionListener{//extends is Java's way of inheriting other classes
  17.         Container context = getContentPane();//places the Container inside the JFrame
  19.         JButton button = new JButton("BUTTON");//creates a button!! and names it "BUTTON"
  20.         JButton button2 = new JButton("BUTTON2");//same same
  21.         JButton button3 = new JButton("BUTTON3");//same same
  23.         mainGUI(){//constructor IMPORTANT!! you MUST place ALL formatting of you GUI in the CONSTRUCTOR!!
  24.                 context.setLayout(new FlowLayout(FlowLayout.CENTER));//sets the layout of the GUI to a center flow, meaning
  25.                         //everything will be in the center of the GUI
  27.                 context.add(button);//places the button inside of the GUI
  28.                 context.add(button2);//same same
  29.                 context.add(button3);//same same
  31.                 //ADDED!!!!!!!!!!!!!!!
  33.                 button.addActionListener(this);//IMPORTANT this places a listener on the button
  34.                 button2.addActionListener(this);//same same
  35.                 button3.addActionListener(this);//same same
  36.                 //if the actionlistners are not added it will NOT work
  38.                 //IMPORTANT the order you place the components in the GUI is the order they APPEAR!!
  40.                 //EXTRA!!!!
  42.                 //FUN with colours!
  44.                 context.setBackground(;
  45.                 button.setBackground(;
  46.                 button2.setBackground(;
  47.                 button3.setBackground(;
  48.         }
  50.         public void actionPerformed(ActionEvent ae){           
  51.                 if(ae.getActionCommand()=="BUTTON"){context.setBackground(;}//if a button with the text BUTTON is pressed change the background color
  52.                 if(ae.getActionCommand()=="BUTTON2"){context.setBackground(;}//almost same derive
  53.                 if(ae.getActionCommand()=="BUTTON3"){context.setBackground(;}//almost same derive
  54.                 //getActionCommand allows the program to read which button text is being pressed
  55.         }
  57.         public static void main(String args[]){
  58.                 mainGUI main = new mainGUI();// when this is run from here it executes your CONSTRUCTOR
  59.                                 //bascially it MAKES the GUI
  61.                 main.setVisible(true);//you have to be able to SEE it
  62.                 main.pack();//makes it pretty
  63.       ;//updates the GUI to show everything
  64.                 main.setResizable(false);//EXTRA makes it so that you can resize DUH!!
  65.                 main.setTitle("TITLE HERE");//obvious...
  67.                 main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//makes it so that when you press the X it closes
  68.         }
  69. }

Remember you MUST add the ActionListener to each and every button.

Comments, Questions, Concerns post 'em below.

Java / Beginning of GUI -- Java
« on: April 23, 2010, 07:56:08 pm »
A GUI or Graphics User Interface is pretty pictures which the user sees when interacts with your program for example the boxes you press in Minesweeper is a GUI.

One of the biggest advantages of Java is that it is very simple to create a front end or GUI. The only real big hurtle in doing so in Java is learning the classes and all the components as well as the order which it must be coded.

Well to start off you must know the symantics and the lingo of the setup of a GUI in Java.

In Java there is something called a "JFrame" which the basically the box border which you view everything in. Then there are "JPanel" which is what holds all your components and interfacing devices. The last most important component is the "Container" which holds the JPanels inside of the JFrame.

Let's jump into some code!!!

Code: Java
  1. /*
  2. //
  3. //@author: GodLord
  4. //
  5. */
  7. import javax.swing.*;//all required to use the correct classes to create a
  8. import java.awt.*;//healthy GUI system
  9. import java.util.*;
  12. public class mainGUI extends JFrame{//extends is Java's way of inheriting other classes
  14.         Container context = getContentPane();//places the Container inside the JFrame
  16.         JButton button = new JButton("BUTTON");//creates a button!! and names it "BUTTON"
  17.         JButton button2 = new JButton("BUTTON2");//same same
  18.         JButton button3 = new JButton("BUTTON3");//same same
  20.         mainGUI(){//constructor IMPORTANT!! you MUST place ALL formatting of you GUI in the CONSTRUCTOR!!
  21.                 context.setLayout(new FlowLayout(FlowLayout.CENTER));//sets the layout of the GUI to a center flow, meaning
  22.                         //everything will be in the center of the GUI
  24.                 context.add(button);//places the button inside of the GUI
  25.                 context.add(button2);//same same
  26.                 context.add(button3);//same same
  28.                 //IMPORTANT the order you place the components in the GUI is the order they APPEAR!!
  30.                 //EXTRA!!!!
  32.                 //FUN with colours!
  34.                 context.setBackground(;
  35.                 button.setBackground(;
  36.                 button2.setBackground(;
  37.                 button3.setBackground(;
  38.         }
  40.         public static void main(String args[]){
  41.                 mainGUI main = new mainGUI();// when this is run from here it executes your CONSTRUCTOR
  42.                                 //bascially it MAKES the GUI
  44.                 main.setVisible(true);//you have to be able to SEE it
  45.                 main.pack();//makes it pretty
  46.       ;//updates the GUI to show everything
  47.                 main.setResizable(false);//EXTRA makes it so that you can resize DUH!!
  48.                 main.setTitle("TITLE HERE");//obvious...
  50.                 main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//makes it so that when you press the X it closes
  51.         }
  52. }

NOTE: This was just made in a few minutes, if it doesn't work respond otherwise:

Comments, Questions Concerns Below.

Java / Introduction to Graphics -- Java
« on: January 11, 2010, 06:20:50 pm »
In Java you can create applications called Applets they are basically what most Java programs are made up of. Applets are used for GUI and such making your text based Java programs pretty.

Thus far we have been only making text based Java programs now if you were to make that into an executable jar file it wouldn't run on a JavaRunTime Environment on your standard box. So in order for the Environment to see the code and display it to your screen you have to make use of Applets or using some Window Panel that are put into the Java library.

However if you understand how Applets work you can create your own sort of panel.

Without further to do the code:

Code: Java
  1. /*
  2.  * Demonstrates a basic applet
  3.  *
  4.  * @author GodLord
  5.  */
  8. import java.applet.Applet;//Imported to be able to use applets very important
  9. import java.awt.*;//Import so you can use the standard drawing library
  11. public class Einstein extends Applet{//Notice there is an "extends Applet" syntax this tells the compiler it is to be
  12.                                                 //an Applet~~~~~~~~~~
  13.         //-------------------------------------------------------
  14.         //Draws a quotation by Albert Einstein among some shapes
  15.         //-------------------------------------------------------      
  16.         public void paint(Graphics page)//Notice there is NO main method invoked, instead there is this syntax
  17.         {
  18.                 //Here are the draw methods they are obvious
  20.                 page.drawRect(50, 50, 40, 40);
  21.                            //the parameters for Rect(x-coord, y-coord, width, height)
  22.                 page.drawRect(60, 80, 225, 30);
  23.                             //the parameters for Rect(x-coord, y-coord, width, height)
  24.                 page.drawOval(75, 65, 20, 20);
  25.                             //the parameters for Oval(x-coord, y-coord, width, height)
  26.                 page.drawLine(35, 60, 100, 120);
  27.                             //the parameters for Line(x1-coord, y1-coord, x2-coord, y2-coord)
  29.                 page.drawString("Out of clutter, find simplicity.", 110, 70);
  30.                                                                               //the parameters String("String", x-coord, y-coord)
  31.                 page.drawString("-- Albert Einstein", 130, 100);
  32.                                                                               //the parameters String("String", x-coord, y-coord)
  33.         }
  37. }
Questions, comments and such below.

Java / The for loop - Java
« on: January 09, 2010, 01:04:38 am »
All right like many loops such as the while loop the for loop has four major parts: initialization, condition, increment and the code body here is the basic syntax:
Code: Java
  1. for(initialization; condition; increment;)
  2. {
  3.         code body;
  4. }

So lets say we want to count to 10 and print out all the values, lets start counting say at 0:
Code: Java
  1. public class ForLoops
  2. {
  3.         public static void main(String args[])
  4.         {
  5.                 for(int x = 0; x<=10; x++)
  6.                 {
  7.                         System.out.print("Counting: " + x);
  8.                 }
  9.          }
  10. }

There you have it this code will now create an integer called "x" then check to see if "x" is less than or equal to 10 if it is then it shall execute the code body once then increment "x" by one(which means adds 1 to x) and checks the condition again, and loops and etc. As long as the condition is true it'll keep looping until it's false then fall through.

There you have it similar to the other loops the for loop.

Questions, comments and such post 'em below.

C++ / Read/Write to a text file?
« on: January 06, 2010, 04:50:43 pm »
How would you accomplish reading a .txt file then writing to the .txt file changing it, etc.

General Talk / Java to .exe?
« on: January 01, 2010, 11:12:21 pm »
Does anyone know if it's possible to make a java class file into a .exe program? This is one of my major reasons for wanting to switch to a C language. I'll continue to learn java however I'm just curious as to if it's possible, it would be really nice if it was.

General Talk / Is Java Dead?
« on: December 30, 2009, 05:29:36 pm »
There seems to be the ever lying fact that languages do die, beginning that I program in Java I'm worried about this. I like the language it is simple and many of the tasks you want to do can be found already in prebuilt classes, it's nice. I just want the views of this community on the subject: Do you think Java is dead, dying? How long do you presume it'll last? Is it still used in the real world?

Java / Conditional modifiers -- Java
« on: December 21, 2009, 10:02:19 pm »
Before we continued on our journey through the Java language I felt it necessary to familiarize you with the conditional modifiers that are mostly universal to all languages. These will become necessary when starting logic statements. In order to make these, make sense it would be best to present them in an example rather than a list to see the practicality.

Code: Java
  1. public class conditionalModifiers
  2. {
  3.         public static void main(String args[])
  4.         {
  5.                 int x = 0;
  6.                 int y = 0;
  7.                 int z = 0;
  8.                 if(x == 0)
  9.                 {
  10.                         System.out.println("X is equal to 0");
  11.                 }
  12.                 if(y != 1)
  13.                 {
  14.                         System.out.println("Y is not equal to 1");  
  15.                 }
  16.                 if(x == 0 || y != 0)
  17.                 {
  18.                         System.out.println("X is equal to zero OR Y is not equal to 0");
  19.                 }
  20.                 if(x == 0 && y == 0)
  21.                 {
  22.                         System.out.println("X is equal to zero AND Y is equal to zero");
  23.                 }
  24.                 while(z == 0 && z != 1)
  25.                 {
  26.                         System.out.println("Z is equal to zero AND Z is not equal to 1");
  27.                         z = 10;
  28.                 }
  29.         }
  30. }

Hope this clears up some things.......probably more questions now....

Questions, comments and such post below.

General Talk / Are there any Java programmer left here?
« on: December 21, 2009, 09:42:12 pm »
I am 100% willing to teach young aspiring Java programmers. However I am seeing that no one seems to have interest in them. I will continue to post them whenever I have free time, but I want to know is there is actually anyone who wants to learn left.

Questions, comments and such post below.

Java / The while loop -- Java
« on: December 21, 2009, 09:36:27 pm »
In Java, much like in every other language, you have loops. Loops are constantly reoccurring code which keep replaying over and over until the statement in the condition area is turned false. Before I go further here is the syntax:
Code: Java
  1. while(condition area)
  2. {
  3.         loop this while condition is true;
  4.         once false drop out of loop;
  5. }

Whenever loops are introduced it is normal that they are showed as a counter. Let's get into the code:
Code: Java
  1. public class usingWhileLoop
  2. {
  3.         public static void main(String args[])
  4.         {
  5.                 int x = 0;//initialize integer to be used in the loop as the condition
  6.                 while(x!=10)//this says to loop the code in the block while x is not equal to 10
  7.                 {
  8.                         System.out.println("Counting: " + x);//this displays "Counting: " with the integer value following in the first case it'll be 0
  9.                         x++;//this adds one to the integer x so that the loop eventually becomes false and drops through
  10.                 }
  11.                 System.out.println("Done...");//displays "Done..." once the loop falls through
  12.         }
  13. }
There you have it a basic counter in Java, play around with the values of x and change the conditional if you wish, just become comfortable with this until you move on to more complicated loops.

Questions, comments and such post below.

Java / The if statement -- Java
« on: October 18, 2009, 05:16:05 pm »
In computer languages you have logic involved as you do in everyday life. One of the many logic statements is the if statement. A logic statement basically just checks for a condition in it's own way and executes a line if true. Our first step is to learn the most basic of all statements the if statement. Here is the set up:

Code: Java
  1. if (condition)
  2. {
  3.         (do this if condition is true)
  4. }
This can be used in a variety of ways however for the simplicity of this tutorial I will show the most basic way I can derive:

Code: Java
  1. import java.lang.*;
  2. public class usingIfstatement
  3. {
  4.         public static void main(String args[])
  5.         {
  6.                 int an_integer = 1;//this makes an integer value called "an_integer" and sets it equal to 1
  7.                 if(an_integer == 1)//notice when using logic "==" means "equal to" remember this because there are two
  8.                                  //instead of one as used when assigning a value to anything
  9.                 {
  10.                          System.out.println("The value is 1.");//prints the message
  11.                 }
  12.         }
  13. }
When ran this will print the line "The value is 1." however if you change the integer value to something like 10, and NOT the condition then it will print nothing and exits the application. Play around with this if you have any questions I will be glad to help.

Java / Input (Keyboard class) -- Java
« on: October 11, 2009, 05:46:56 pm »
In Java you can accept input in a variety of ways on of them is to use the Keyboard class.
Code: Java
  1. import cs1.Keyboard;
  2. public class aClass
  3. {
  4.         public static void main(String args[])
  5.         {
  6.                  int input;
  7.                  input = Keyboard.readInt();
  8.                  System.out.println(input);
  9.          }
  10. }
What this does is create an integer, reads the value inputed from the user and assigns it to that integer. Then prints the integer which was inputed. The use of the Keyboard class will become apparent in later tutorials for now know that this is one of the ways to read inputs from the user of the program.

[edited name=Nathan Adams date=1255305671][/edited]

Java / "Hello World" Application -- Java
« on: September 21, 2009, 11:52:40 pm »
So I'm back, for now, to inform anyone who wants to know about Java. At the moment my knowledge is limited but I believe I understand enough to write a few simple tutorials. As always with languages you have to learn how to print the simple "Hello World" to the screen. So here is goes:
Code: Java
  1. import java.lang.*; //This is automatically imported and includes the standard java library
  2.                               //as in other languages you have other "functions" stored in different
  3.                              //directories but for now we are sticking to standard
  5. public class HelloWorld //This is the name of your application known as a class file
  6. {
  7.         public static void main(String args[]) // Main entry point into the application basically the "int main(void)" of Java
  8.                 {
  9.                          System.out.println("Hello World"); //Java has it's "functions" written in embedded classes so you have to
  10.                                                                                //tell it exactly where it is. This is the printing "function" known in C++
  11.                                                                                //as "cout << "Hello World";
  12.                          return; //Old habit of mine, I began writing in C. You don't technically need this but it is good practice
  13.                                          //for when we go over returns
  14.                  }
  15. }
For complete beginners I shall explain commenting used here. Everything after '//' is a comment and isn't used in the actual program you don't need comments I only put them here for your understanding of what I was doing since this is a tutorial.

If you don't have a compiler you might want to check out an earlier post of mine called: Java Compiler(IDE) read everything there including other posts not just the original install the JDK(Java Development Kit) which is the environment for Java to run in and the IDE jGrasp to write actual code.
At requests I might go over how, in a tutorial, to use the IDE jGrasp but it is pretty straight forward.

A reminder once you have named your class for the application you can not change it without having to change everything else in your program, such as if I were to compile this with the name "HelloWorld" and decide I want it to be "HelloWorlds" I would need to either write a new program or redirect each line to the original class of "HelloWorld", in other words just keep it the same throughout and pick a name you'd keep.

[edited name=Nathan Adams date=1255216768][/edited]

Java / Java Compiler(IDE)
« on: September 01, 2009, 10:16:32 pm »
Some of you might know, or not know, I am taking a Computer Science course focused around Java. In my attempts to learn on my own I found a nice little, it is really small, compiler for Java (it also compiles C/C++, Ada95, VHDL, and Objective-C).

Here is the site:

Standard setup nothing fancy or hard.

Questions, comments post 'em below.

C / Arrays
« on: August 08, 2009, 01:52:13 am »
Arrays often show up when you want to store a group of variables of the same type. One way to think about this is a tic-tac-toe board where the upper left is 0 and the bottom right is 8. Also arrays do not start at 1 they start at 0 so if you were to declare an array of 9 you'd actually have ten spaces and since there are only 9 on a board you only need to declare 8.
So the basic syntax of an array is as follows:
Code: [Select]
int examplearray[100]; /* This declares an array */This would make an array of 100 spaces starting at 0 to 99 so if you tried to access element 100 of this array it wouldn't be possible.
Now take this into account:
Code: [Select]
char astring[100]; What could you do with this well you could make it into a string (text) since C doesn't have a built-in datatype for strings you can make an array to store what a string could.
Here is an example:
Code: [Select]
char astring[10];
int i = 0;
scanf( "%s", astring );
for ( i = 0; i < 10; ++i )
    if ( astring[i] == 'a' )
        printf( "You entered an a!\n" );
  /* For learning purposes I am not going to
    go through the entire alphabet */
All this program does is initialize an array with 10 elements, looks for an entry to the array you just made and doesn't let it exceed 10 and if you entered an 'a' it says so.

C / Structures
« on: August 08, 2009, 01:38:06 am »
To start off a structure is basically a group of related variables that are all stored under the same "name." For example you use an address book to store people's names under certain letters such as "Amy" you would store under the letter 'A.' With that said lets move on to a basic struct syntax:
Code: [Select]
struct Tag {
Where Tag is the name of the entire type of structure and Members are the variables within the struct. To actually create a single structure the syntax is:
Code: [Select]
struct Tag name_of_single_structure;To access a variable of the structure it goes:
Code: [Select]
name_of_single_structure.name_of_variable;For example if you wanted to store people's names in a struct you would do something similar to this:
Code: [Select]
struct database {
    char person_1[100];/*This is an array however C doesn't have string capabilities so this will do
                           more talk about arrays next*/
    char person_2[100];
    char person_3[100];

int main()
  struct database directory;  /* There is now an directory variable that has
                              modifiable variables inside it.*/
  strcpy(directory.person_1, "Amy");
  strcpy(directory.person_2, "Andi");
  strcpy(directory.person_3, "Sloane");
You can include any variable type inside of structures not just strings:
Code: [Select]
struct variables {
    int x;
    int y;
    char z[256];
    bool DECISION;

int main()
    struct variables mystruc; /* Remember to always tell the complier
                                              what you want it called by */
    mystruc.x = NULL;
    mystruc.y = NULL;
    mystruc.z = "Text";
    mystruc.DECISION = 0;

Corrected copy methods. -Celestialkey -
[edited name=GodLord date=1249714431][/edited]
[edited name=GodLord date=1249714541][/edited]
[edited name=GodLord date=1249714566][/edited]

C / The switch case
« on: August 05, 2009, 05:18:40 pm »
One of the most useful things for making decisions in C is the switch case basic syntax is as follows:
Code: [Select]
switch ( <variable> ) {
case this-value:
  Code to execute if <variable> == this-value
case that-value:
  Code to execute if <variable> == that-value
  Code to execute if <variable> does not equal the value following any of the cases
It can be thoughts as a substitution for a series of if statements.
Don't forget the breaks I have done this many times and for some reason my complier doesn't pick it up....
A basic example:
Code: [Select]
int a = 10;
int b = 10;
int c = 20;

switch ( a ) {
case b:
  /* Code */
case c:
  /* Code */
  /* Code */
As I said before a useful application of the switch case is decision  making such as if you are deciding to either add, subtract, multiply or divide on a calculator. Or deciding to start a new game, load an old game or play multi player in video games. He is an example:
Code: [Select]
#include <stdio.h>

void playgame();
void loadgame();
void playmultiplayer();

int main()
    int input;

    printf( "1. Play game\n" );
    printf( "2. Load game\n" );
    printf( "3. Play multiplayer\n" );
    printf( "4. Exit\n" );
    printf( "Selection: " );
    scanf( "%d", &input );
    switch ( input ) {
        case 1:            /* Note the colon, not a semicolon */
        case 2:         
        case 3:         
        case 4:       
            printf( "Thanks for playing!\n" );
            printf( "Bad input, quitting!\n" );

The functions here are prototypes thus do nothing this is only to show how a switch case can be used.
The program does this creates a variable for input of decision gives the options that are programed in with the printf function, then looks to see when it is changed or "switched" to another input value. Example if I put in 2 when it asks it'll go to case 2 and run that when it is over it breaks when it is done exiting the program.
This program will not work because the functions made are not referenced in a return so they don't know what to do thus can't and won't compile.

C / Functions
« on: August 05, 2009, 05:00:04 pm »
In any language a function is something that the programmer makes to make things easier for him/her in the long run. But to start lets give you the basic structure of a function:
Code: [Select]
thereturnofthefunction nameofthefunction (passingparametersofthefunction)
{ what the function does while the parameters and/or returns?}
This can be all confusing at first but let me give you an example to make sense of it:
Code: [Select]
void PrintThis()
Now you can see what I was talking about since all this is doing is printing something it doesn't return anything thus void is a holder meaning nothing is returning. "PrintThis" is just the name of the function you can call it whatever you like however it is good practice to name it according to what it does. Next I am not giving this function anything to pass so I don't need to put anything in the ( ) if I wanted to I could of put another void as a holder (void). Last I tell it what I want it to do to print on the screen "This."
In reality functions are used with returns and parameters so let me give you an example of something which uses all the places of the function:
Code: [Select]
int ADD(int x, int y);
So as you can see the name of the function is ADD it passes integer x and integer y through and returns the value as an integer thus is why I put int in the beginning. This is known as a prototype function.
When this kind of function is used inside of a program you have to initialize the variables which it is passes through the function
You have to name the integers in the main body the integers named in the function are just there to tell the function that it will be passing integers through it kind of a warning to the function
Thus when using it in a program it looks like this, also you can put a function in the top or bottom of the program it doesn't matter but my practice puts it in the top:
Code: [Select]
#include <stdio.h>

int ADD( int x, int y );

int main()
  int x;
  int y;
  printf( "Please input two numbers to be added: " );
  scanf( "%d", &x );
  scanf( "%d", &y );
  printf( "The sumt of your two numbers is %d\n", ADD( x, y ) );

int ADD(int x, int y)
  return x + y;

C / Loops
« on: August 05, 2009, 04:30:07 pm »
In the past people have split up the different types of loops into different sections however I will cover most of the types here.

The for loop
To begin with there is the for loop whose syntax is such:
Code: [Select]
for ( variable initialization; condition; variable update ) {
  Code to execute while the condition is true
The for loop can be thought as a major shortcut because you can make a variable set a condition and manipulate the variable all in one place. So instead of this in main:
Code: [Select]
int X;
X = 1;
if (X < 10)
   X++;//The ++ manipulator just adds one to the value
}//As you can see this will only check once and print X once then add it once but lets say you can to print 1 through 10 all in one.
This when you can use a for loop a loop keeps going over and over until proven false:
Code: [Select]
int x;
    /* The loop goes while x < 10, and x increases by one every loop*/
    for ( x = 0; x < 10; x++ ) {
        /* Keep in mind that the loop condition checks
           the conditional statement before it loops again.
           consequently, when x equals 10 the loop breaks.
           x is updated before the condition is checked. */   
        printf("%d\n" x );//The crazy "%d\n" just makes it jump to the next line down so that it doesn't print on the same line.
The while loop
The while loop in contrast to the for loop is much more simpler but requires more in the body here is the basic construction:
Code: [Select]
while ( condition ) {
 Code to execute while the condition is true }
Comparing the while loop to the if statement show similar construction, but the while loop, loops making it different it will keep going until the condition is false or the condition no longer exists.
So to do the same thing as the for loop did you use this:
Code: [Select]
int x = 0;  /* Don't forget to declare variables */
  while ( x < 10 ) { /* While x is less than 10 */
      printf( "%d\n", x );
      x++;             /* Update x so the condition can be met eventually */
do while do loops
These types of loops are useful if you only want something to loop once here is the syntax:
Code: [Select]
do {
} while ( condition );
Here is an example:
Code: [Select]
int x;

  x = 0;
  do {
    /* This will print x while x is
     not equal to 0*/
    printf( "%d\n", x );
  } while ( x != 0 );

C / The if conditional statement
« on: August 05, 2009, 04:07:39 pm »
In order to understand how conditional statements work you have to be able to understand how the condition part works. In C they are known as relational operators:
Code: [Select]
>     greater than              5 > 4 is TRUE
<     less than                 4 < 5 is TRUE
>=    greater than or equal     4 >= 4 is TRUE
<=    less than or equal        3 <= 4 is TRUE
==    equal to                  5 == 5 is TRUE
!=    not equal to              5 != 4 is TRUE
The most basic of the conditional statements is the if statement it is used as such:
Code: [Select]
if ( statement is TRUE ){
    Execute this line of code}
So as you might of guessed by now your condition goes inside of the ( ) and if that is TRUE then it executes what's inside of the { }. Here is a simple example that shows the use of the syntax:
Code: [Select]
if ( 5 < 10 ){
    printf( "Five is now less than ten." )}
This simple prints "Five is now less than ten" if 5 is less than ten and since this is always true this condition will fall through and do what is in the { }.
However lets say you want to see is something is true or false then you would need to include an else statement used such as:
Code: [Select]
if ( TRUE ) {
  /* Execute these statements if TRUE */
else {
  /* Execute these statements if FALSE */
So lets use the previous example:
Code: [Select]
if( 5 == 10)//This will never be true
    printf("Impossible");//So it doesn't do this
   printf("Possible");//Does this
But now lets say you want to see if a specific variable is equal to a specific value for simplicity lets say variable X is equal to 10.
You could have it check in two if statements or you could use an else if statement this is used similarly to else however the else if can accept a condition:
Code: [Select]
if ( X != 10)//We know this is false
   printf("Ten is not equal to X.");//It doesn't do this
else if ( X == 10)//We know this is true
   printf("Ten is equal to X.");//It does this

General Talk / Possibly might not be back.....
« on: August 03, 2009, 11:33:32 pm »
Recently I have been doing some events around where I am currently residing, Florida every summer -.-, and something has happened. The outcome of this something could possibly limit or cancel me from returning to this site. This is just a notification if anyone is wondering why I am not on that often or etc. However do not take this post as me saying goodbye that time is a long ways away from now and probably won't happen. I do love this site and it is dear to me but I have to be let loose for awhile this is mainly my own fault... Anyway take care and hopefully I will be back before you know it, thanks.

Challenges / Challenge Weird Progarm Execution.
« on: August 01, 2009, 10:00:23 pm »
Here is the challenge:
Why does the code that I provide whenever a entry is entered only recognizes everything as even?
It fully complies so it's not a syntax error.
Code: [Select]
#include <iostream>
#include <windows.h>
#include <string>

using namespace std;

int main()

cout << "Hello World!\n";
string CHOICE;
cout << "If you wish to exit do so by typing \"exit\" now otherwise type \"no\"\n";
cin >> CHOICE;
if(CHOICE == "exit")
cout << "Exiting...";
return 0;
cout << "Pick 1-10\n" << "If you wish to exit from here type in 0 (zero)\n";
int choice = NULL; //Resets choice to nothing
cin >> choice;
if(choice == 2, 4, 6, 8, 10)  //Sees if it's even
cout << "It is even\n";
goto Beginning;
else if(choice == 1, 3, 5, 7, 9)  //Sees if it's odd
cout << "It is odd\n";
goto Beginning;
else if(choice == 0)   //Sees if it's zero the exit command
cout << "Exiting...\n";
     return 0;
else  //Sees is it's invalid
cout << "Invalid entry.\n";
goto Beginning;


I put weird things in my programs to make myself self-assured, "feel-better".
This is mainly for the people that are starting out it's really simple so Celestialkey and other admins/moderators if you know the answer don't post it here for the people still thinking to give them a chance, thanks.

General Talk / GunZ Evaluation
« on: August 01, 2009, 02:17:23 am »
This is for NightSky and for another person that wishes to evaluate my GunZ game-play.
I am not a 'pro' nor am I any good I am a horrible player only waste your time watching this, if you are looking for a good replay you're out of luck, if you wish to help me in my game-play in the game of GunZ then here evaluate.
Another reason I posted this here instead of PMed you NightSky was because I would like Celestialkey to evaluate too, if he has time, and any others.

C++ / Calculator program problem
« on: July 30, 2009, 10:20:09 pm »
I dug up an old calculator program and for those of you that don't know I teach a programming class, RobotC, for robotics. Anyway so I had some extra time and I tried to teach some of my friends some C++ syntax and when I tried to show them how this program works and it doesn't I was running it in Visual C++ Microsoft Express Edition and it didn't work. So I tried the program in the old trustworthy CodeBlocks complier and it works. Here is the code:
Code: [Select]
#include <iostream>
#include <windows.h>

using namespace std;

void Add(int a, int b)

    cout << "The sum of the two numbers are";
    cout << a+b << endl;

void Sub(int a, int b)
    cout << "The sum of the two numbers are";
    cout << a-b << endl;

void Div(float a, float b)
    cout << "When divided the numbers are";
    cout << a/b << endl;

void Mul(int a, int b)
    cout << "When multiplied the numbers are";
    cout << a*b << endl;

int main(void)

        cout << "Welcome to Calculator!\n";
        cout << "Input 1 for addition, 2 for subtraction, 3 for division or 4 for multiplication\n";
        cout << "5 to quit and exit\n";
        int choice;
        cin >> choice;
            case 1:
            cout << "Input numbers to be added\n";
            int a,b;
            cin >> a;
            cin >> b;
            goto Jump1;
            case 2:
            cout << "Input numbers to be subtracted\n";
            int c,d;
            cin >> c;
            cin >> d;
            goto Jump1;
            case 3:
            cout << "Input numbers to be divided\n";
            float e,f;
            cin >> e;
            cin >> f;
            goto Jump1;
            case 4:
            cout << "Input numbers to be multiplied\n";
            int g,h;
            cin >> g;
            cin >> h;
            goto Jump1;
            case 5:
            return 0;
            cout << "Error crash";
            return 0;


        return 0;

Here is what the complier tells me in Visual C++:
Code: [Select]
------ Build started: Project: Calculator, Configuration: Debug Win32 ------
Embedding manifest...
.\Debug\Calculator.exe.intermediate.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.
Build log was saved at "file://c:\Documents and Settings\*EDITED*\My Documents\Visual Studio 2008\Projects\Calculator\Calculator\Debug\BuildLog.htm"
Calculator - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I believe it's something obvious but I can't find anything wrong in the code so....

General Talk / Best book for learning C++
« on: July 25, 2009, 09:50:52 pm »
I have learned a lot from this site and in search for more knowledge from C++ I want to get a book. In my search I have come across a lot of books and I am hoping the people in this community can help me make the best choice. All of you know, at least a little, my abilities and I am asking you based on this. So the real question is: what is the best book to learn the C++ programming language from?

General Talk / Different Chat System?
« on: July 19, 2009, 06:32:07 am »
I enjoy the chat box a lot however have you considered using different chat options I have seen XAT chat system work well in the past.

General Talk / I am back.
« on: July 17, 2009, 12:24:46 am »
For those of you whom remember me, hello. To those of you whom I have never met before, a belated welcome and hello. I am a programmer I have gotten into some things which have kept me from this community. However lately I've been wanting some.....colleague? programmers advice, guidance, help and of course just to talk to. If you have any questions about what I've been doing post a question, if you would like me to do anything, help you or such ask I will do so gladly.
I can not say how long I will be able to be in touch will this community hopefully a while. Once again I am back.

Humor / Google Error
« on: April 08, 2009, 03:51:36 pm »
Is this possible?????

Pages: [1] 2


* Search

* Recent Posts

Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]

Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]

Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]

Updates by Nathan
[October 30, 2015, 08:27:36 pm]

Re: Client-Server Messaging by Nathan
[October 25, 2015, 05:48:57 pm]