Monday, November 24, 2008

Photosynth - interesting initiative from Microsoft

On August 20, 2008, Microsoft officially released Photosynth to the public, allowing users to upload their images and generate their own Photosynth models. What is photosynth?

Photosynth is a software application from Microsoft Live Labs and the University of Washington that analyzes digital photographs to build a three-dimensional point cloud of a photographed object.

Pattern recognition components compare portions of images to create points, which are then compared to convert the image into a model. Users are able to view and generate their own models using a software tool available for download at the Photosynth website.

Here is an excellent video presentation from ted (please select flash version below):



So why is this interesting? Well, often we do not know what can emerge from new technologies like this. But one of the most obvious reason why this is interesting, is because it connects digital images together with respect to the content. This basically means that we're creating a large scaled network of images which is browsable and searchable. And over time we can develop very presice 3D-models of cities and certain objects around the world. Maybe this data and these models can help us develop better navigational tools and synthetic vision for other scientific fields, such as robotics.


_________________________________________________________
Further reading and sources:
Original website of video
Wikipedia - Microsoft Live Labs Photosynth
Photosynth website

Saturday, July 12, 2008

Monkey eating marshmallow using only its mind

The monkey uses a robotic arm, which it controls using only signals from its brain.

So why would a monkey be eating marshmallows with a semi cyborg arm? The answer is simple. It's hungry for a snack, and its arms are stuck. What options are there, but to utilize a robotic arm to fulfill its sweet desires? Not many, and it seems the monkey is pleased with this innovative solution.



This innovation could benefit people with paralysis and spinal cord injuries. The goal is to make a prosthetic device for people with total paralysis, and ultimately to better understand brain complexity.

Scientific experiments with animals are often topics of ehtical discussions. We contacted Michele D. Baum a resource person from the university conducting this experiment to ask a couple of questions (University of Pittsburgh Schools of the Health Sciences).

Q: How were the monkeys treated?
A: "...I can tell you that the monkeys are well cared for. Primate research is expensive, with each individual monkey costing more than $10,000. Beyond that, the U.S. National Institutes of Health and other funders invest large amounts of money into research that is often animal-based. It would not make sense to mistreat the monkeys. They are very well cared for."

Q: Is surgery required to interpret the signals from the brain of a monkey?
A: "The monkeys do have small arrays of electrodes, about the size of half a thumbtack, implanted on the surface of their brains. The electrodes themselves are very thin -- no wider than a human hair. The brain is not exposed. The brain also has no pain sensors and the implant is not painful to the monkey. Researchers often work with the same animal for many years. If the animal was not comfortable, it would not work, and the data collected would not be valid."

Thank you for your answers.


_________________________________________________________
Further reading and sources:
Mind over matter
Science Daily - Mind over matter

Tuesday, June 10, 2008

The basics of Java

The list of guides and tutorials describing the basic features of Java is endless (not literally of course). Instead of making yet another complete tutorial covering the basics of Java, this lecture will only briefly introduce the basics of Java. If you are a somewhat experienced programmer this short introduction might very well be all you are looking for. If not, that is, you are new to programming in general, it is recommended that you read one of the more careful tutorials available online covering the basics of Java, for instance Suns tutorials.

Assumptions

In the following I will assume your knowledge about common programming terms, for instance like pointers, variables, methods, constructors, classes and objects, and their attributes. How declaration of these are done in Java will on the other hand be shown.

Installing an IDE
An integrated development environment (IDE) is, simply put, a software combining the process of editing, compiling and executing. In an IDE the editor is typically a graphical text editor with spell checking, syntax highlighting and code folding, and the IDE makes compiling and executing the application effortless.

For beginners not known to the basics of compiling and execution it is not recommended to use an IDE, but instead only download the Java SE Development Kit (JDK) from here. The JDK includes Java Runtime Environment (JRE), which is required to run Java applications. For other users it is recommended to download the JDK bundled with NetBeans IDE from the same site. Alternative IDEs for Java is Eclipse and JCreator. It is interesting to note that both NetBeans and Eclipse is mainly written in Java.

Installing the JDK or the IDE is like installing any other application, so I trust you are able to do this without any guidance.

If you have decided to install only the JDK you need to add "installation/location/bin" to your global path and, if it is not already present, add "." to your class-path (the "." will make a Java-class able to use other classes in the same directory). The coding itself is the same as if you had installed an IDE, only you will be writing in a simple text editor and should save the code file as plain text, for instance as a text file named "MySource.java". Compiling a Java source code is done by writing "javac MySource.java" in a command line prompt positioned in the same directory as your saved source code, and execution can then be performed by writing "java MySource".

Creating the your first Java application
If you installed the NetBeans IDE you can create a new project by choosing "New Project..." in the "File"-menu. Select "Java" in field below "Categories:" and "Java Application" below "Projects:". Proceed to the next step by selecting "Next >". Here write the name of the project. By default NetBeans will create one package, a collection of classes, by the name of the project. The main class, the class that will be executed by the runtime environment, is by default simply named "Main". Normally this is not anything to fuss about, so simply click the "Finish"-button after typing the name of the project.

NetBeans will now display the initial class named "Main" (or whatever you decided to name your main class). The code between "/*" and "*/" are comments to the programmer. The code between "/**" and "*/" are also comments, but in addition these comments will be included in the automatically generated Java documentation if it is present just prior to protected or public classes, methods or object/class variables. If only the rest of a line is to be commented, one simply writes "//", these comments will not be included in the documentation. Viewing the code in light of these facts, there are only five lines of code:

1   package javaapplication1;
2 public class Main {
3 public static void main(String[] args) {
4 }
5 }

The first line simply states that this class is a part of a package, here "javaapplication1". The second line creates a class, here named "Main", by the statement "class Main", and that this class is set to be visible to the entire system, that is, "public". Line three creates a method named "main". This will be the entry point of your application, that is, the runtime environment will always provide control to this method in your main class. It should be declared "public", meaning that it is visible to the system, "static", that is, being a method bound to the class itself, and "void", meaning that it does not return anything. The parameter "String[] args" states that the invoker should provide a (possibly empty) list of multiple elements, called an array, of the type "String", that is a standard text object of possibly multiple characters. The elements of this array will be the arguments the executor provides, if you are executing the program from a command line prompt, the elements is the text written after "java MySource", for instance "java MySource argument1 argument2" will result in a list of two elements. The list can be accessed by the variable "args", which is a pointer. Line four and five indicates the end of the "main"-method and the "Main"-class, respectively.

Lets make the application display "Hello world!". This is simply done by adding the following code between line three and four above:
3.1           System.out.println("Hello world!");

"System" is here a class, like "Main", "out" is a class (static) variable representing a "PrintStream"-object, while "println" is a method in the class "PrintStream".

You can now execute the application in NetBeans by pressing "F6" or by choosing "Run Main Project" from the "Run"-menu. In the output field "Hello world!" should be displayed along with some information about the compiling and execution.

Essential notes about Java-codes
In Java all code must be placed inside classes. The variables declared at the root of a class is unique for each instance of the class if it is not declared "static", then it is bound to the class and common for all its instances.

Inside a class, a static method may only invoke another static method (or itself). This is because the static method does not belong to a object, but to the class itself, so it would not have known in which object the non-static method should be invoked. On the other hand, non-static methods can invoke both static and non-static methods.

To access members of a different class, one needs to inform uniquely the environment in which the member should be accessed. To access a static variable "var" in the class "MyClass", one simply writes "MyClass.var". In order to access a non-static variable "var2" in the same class, one needs to inform in which class instance, that is, in which object, the variable should be accessed. A object pointer to the class is then used, name it for instance "obj", and access is then granted by writing "obj.var2". This object pointer can be declared as following
MyClass obj = new MyClass(...)

where "..." indicates the arguments to the constructor of the class.

The same applies to the methods. To invoke a static method "myMethod()" in "MyClass" one simply writes "MyClass.myMethod()". The non-static method "anotherMethod()" can be invoked by the use of an object pointer "obj" of the class, and write "obj.anotherMethod()". Arguments to the method is placed within the brackets. Multiple methods can be declared with the same name as long as the parameters differ, in number or type. Note that two methods can not both have the same parameters, thought they return different types.

Both variables declared at the root of a class and methods (who must be declared at the root of a class) have access level modifiers. These modifiers determine whether other classes can use these variables or invoke these methods. There are four types of modifiers; "public", "protected", "package" and "private". If declared public "public" it is visible to all classes (as long as the system know where to look for the class). On the other end "private" indicates that only the class itself may access this member. "package", a access level obtained by not using any modifier, states that all classes inside this package should be able to access this member, while "protected" also includes any subclass of this class, even if it is not inside the same package.

Classes may be declared without a modifier or with the modifier "public". The effect of these options are the same as for variables and methods as described above.

Inside a method one may declare new variables. These can not have access level modifiers and are only visible before the closuring bracket corresponding to the first previous starting bracket. The interval a variable is visible is called the scope of the variable. If a variable of the same name is already declared, the use of this name will refer to the first previously declared variable of that name, that is, the variable latest declared.

If you were able to keep up with this introduction you should be able to start programming in Java, thought no-one expects you to be an expert at the time, if you have a half-shaky grip of the syntax, you are probably only a couple of hours of test-programming away from being able to code most applications with the use of the Suns application program interface (API), provided that you know an algorithm for each challenge in question. If you feel not smart at all on Java, it is recommendable that you read a more careful introduction tutorial to Java before proceeding to the next lectures. These lectures will be more advanced and not explain any basics of programming in general, but only the subjects in question, which can be program-technical, like multi-threading, or implementation of efficient algorithms for solving specific problems.

Monday, June 2, 2008

All about lithium-ion-based batteries

Modern portable electrical devices typically use batteries based on lithium-ion or its evolved technology lithium-ion polymer. Older devices used nickel-cadmium- or nickel metal hydride-based batteries. The similarities in advised use between these technologies are not only distinct, but almost complementary, in the meaning that the ideal use of one is (close to) the worst case use of the other. After looking into the history and the resulting myth, advice of proper use of lithium-ion will be presented, and finally we will conclude by looking into the future. Our main focus is on lithium-ion-based batteries in modern laptops.

History and basics

In 1983 the first commercial portable computer running on batteries became available. It used a battery technology based on nickel-cadmium (NiCd). In the next decade batteries based on nickel metal hydride (NiMH) and lithium-ion (LiON) became publicly available. For some time they fought nose-to-nose for customer's acceptance, ultimately leading to the victory of the LiON-based technology. As a result, most portable computers and digital cameras use LiON-based batteries, while mobile phones are typically based on a battery technology evolved from the LiON-technology called lithium-ion polymer (Li-poly), which are more robust to physical damage and cheaper to produce.

The advantages of the LiON-based batteries is its superb energy to weight ratio relative to its competitors, its slow in-use degeneration rate and the lack of a so-called "memory effect", which is both present in NiCd- and NiMH-based batteries. However, there is a great drawback. Batteries based on LiON-technology are ageing from the moment they are manufactured, regardless of whether they are charged or not. This means that an older, but unused battery will last shorter than a identical battery manufactured more recently. However, this disadvantage does not seems to frighten as much as its advantages attract, resulting in a wide use of LiON technology in many portable electrical devices.

In use, a lithium-ion typically lasts between two and three years or 300 to 500 full discharges/charges. The discharge/charge rate presented here is not depended on complete discharge/charge cycles, that is, if half of the battery's capacity is used twice, the sum of these uses counts as one, not two, full discharge/charge. It should be stated that these numbers are not based on the ageing or degenerating previously commented alone, but also on the average use of these batteries. With optimal use one can expect much better result because the degeneration can be somewhat delayed, but more importantly, the degeneration can be, and in most cases are, greatly accelerated.

Myth and the effect of its use
Since a flawed use of NiCd- or NiMH-based batteries often resulted in a distinct lack of power, these batteries' need for full discharge/charge cycles have become publicly known. That is, these batteries ideal use were to fully discharge the batteries before recharging, and during recharging neither use or cancellation were recommended. These batteries were said to remember early charges or discharges, a memory which resulted in lack of power. This effect was and is widely referred to as the batteries "memory effect", and indeed, such improper use of these batteries will result in high degeneration rate.

LiON-based batteries do not provide such a memory effect. Nevertheless, most people still believe this effect is present in all or most batteries still in use, indeed including the batteries used in devices such as laptops. Not only is this a wrong understanding, but the use of this "knowledge", or should we say myth, is also the main contribution resulting in the accelerated degeneration. That is, fully discharging and recharging LiON-based batteries can and often will have crucial effect on the batteries duration.

If close to fully or fully discharged, a LiON-based battery's internal safety circuit opens and it becomes unusable in the sense that it will not recharge. If it is not fully discharged, there exists some boost functions that can be able to reactivate the protection circuit and make the battery recharge. Standard chargers will not perform such a boost. Furthermore, if the battery is fully discharged and has been in such a state form months, a boost function will probably not only fail, but may also be dangerous. In addition, a LiON-based battery is expected to degenerate faster when close to fully discharged than if kept at a somewhat higher charge level rate.

On the other hand, fully charging the battery is also not recommendable. Thought it is not the charging itself that is the problem, the result of keeping a battery fully charged is crucial. As noted, any LiON-based battery degenerates from the day it was manufactured, however, a fully charged battery degenerates much faster, especially in combination with a warm environment. In a environment of 60 degrees Celsius a fully charged battery will within three months typically degenerate to 60 % of its capacity, while a 40 % charged battery in the same environment will only degenerate to 75 % after a year. From these numbers it should be clear keeping LiON-based batteries fully charged will greatly accelerate its degeneration, and indeed, most users who try to follow the old battery-friendly tip of full discharge/charge cycles keep the charger connected after the battery is fully charged, thus resulting in accelerated degeneration.

Proper use
As noted, LiON-based batteries degenerate much faster when kept close to fully or fully charged. In special situation when extra battery life is needed, like on long trips and so on, one must by all means fully charge the battery. Thought, in such situations the battery should be charged only shortly prior to departure in order to keep the battery fully charged as short as possible. However, in normal situations when one simply sits by the outlet, an easy, but not optimal, solution is to disconnect the charger before the charge level reaches 80 % of full capacity. This should also be done prior to journeys where full battery life is not needed.

To avoid the opening of safety circuits and acceleration of degeneration, it is also recommendable to reconnect the charger when charge level is approximately 20 %. Again, if an outlet is not available and the laptop is needed for use, one must of course keep using the laptop. However, it should be a good reason for forcing the last 5 % out of the battery, since both the danger for opening safety circuits and the level of degeneration increase dramatically while approaching a fully discharged state.

The heuristic of disconnecting and reconnecting the charger is often easy to apply, but does not offer the best result. In the case when one is sitting nearby the outlet, which normally is the typical case, the best solution is to disconnect the battery itself. The battery should be disconnected when the charge level is approximately 40 % and stored properly (see "Storing of lithium-ion batteries"). Please note that disconnecting the battery, thought good for the battery itself, increase the risk of loosing your work to what is present for desktop computers. That is, if one has disconnected the battery and the power fails, the laptop will immediately power off, not leaving any "Do you wish to save the changes" or alike. However, thought varying between each location, normally the power is quite stable, so this downside may not be preponderant.

Storing
As is the case in the recommended use of these batteries, nor in storing is it wise to keep the battery at high or low charge level. The recommended storage charge level is 40 %. The reason this charge level is somewhat high is to keep the battery's protection circuit operational during prolonged storage. Thus, if you plan to store the battery for a shorter period, it might be wise to keep it at a lower charge level, say 20 to 30 %.

The storage environment's temperature can be vital for the battery. Thought freezing the battery is not a good idea, the battery should be kept coldly, about 0 degrees Celsius is a generally good rule of thumb.

To see the effect of these rules of thumb, we previously commented the decreased degenerating achieved by storing a battery at a lower charge level, that is, a fully charged battery stored in a 60 degrees Celsius environment will typically degenerate to 60 % within three months, while a battery stored at 40 % charge level will typically only degenerate to 75 % within a year. Furthermore, if the environment had been of 0 degrees Celsius, one could expect the battery to only degenerate to 98 % in a year, which under the circumstances must be stated as an acceptable degeneration rate. Finally it should be noted that the longer one plans to store the battery, the more important it is to keep these guidelines.

Digital memory
As commented, LiON-based batteries does not possess the "memory effect" present in both NiCd- and NiMH-based batteries. Nonetheless, there is a effect present in these batteries referred to as "digital memory", referring to the memory of a fuel estimate present in many devices using batteries, including both laptops and mobile phones. Short discharges and recharges does not provide synchronization of the fuel estimate and battery's state-of-charge. The effect of this "digital memory" is not related physically to the battery, as was the case for the "memory effect", but it will make the fuel estimate increasingly less accurate. To avoid this effect one performs a calibration by fully discharged and then recharge the battery. To eliminate the failure caused by the "digital memory", it is often recommended to perform a calibration once every 30 charge.

Does lithium-ion-based batteries belong to the future?
Since it became commonly available, the use of LiON-based batteries have been discussed, and still is, thought its competitor based on NiMH is not much used. The technology behind the LiON-based batteries have been continuously developed, and the development is still in progress. By obvious reasons it is of particularly interest to decrease the natural ageing of the LiON-based batteries, and progress has been achieved.

Thought development and progress, it should not come as a total surprise if a new technology claim the battery-throne in the near future. After all, the progress of existing technology typically only results in modest improvements, while users and scientists keep dreaming of laptops lasting weeks – or maybe years. Having said that, progress has been unexpectedly slow in the field of new battery technologies for the consumers marked, so it might remain with the dreams for yet some years to come.

_______________________________________________________
History of laptops
Is lithium-ion the ideal battery?
Lithium-ion polymer battery
All about laptop batteries
How to prolong lithium-based batteries
Sweet Nanotech Batteries: Nanotechnology Could Solve Lithium Battery Charging Problems

Tuesday, May 27, 2008

Fun with programming - JavaScript

This is a great example of creative programming. Check out this neat JavaScript.

Instructions. Enter a website that contains a lot of pictures (example). Then copy this script into your adress line, and hit enter.

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName("img"); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+"px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}R++}setInterval('A()',5); void(0);

Neat!

_______________________________________________________
Further reading and source:
StopGeek - Neat trick with JavaScript

Phoenix lands on Mars

24 hours ago NASA's Phoenix spacecraft landed on Mars. It's the first successful Mars landing without airbags since Viking 2 in 1976.

So, what is there do be done on Mars? Well, there is plenty of information to be gathered. The complement of the Phoenix spacecraft and its scientific instruments are ideally suited to uncover clues to the geologic history and the biological potential of the planet. Phoenix will be the first mission to return data from either polar region providing an important contribution to the overall Mars science strategy "Follow the Water".

Follow the water?
Without a clear presence of surface water, it may seem like a strange name for a Mars exploration. How can we follow water, when it doesn't seem like there is any to be found?

Following the water really means looking for scientific evidence that water was present in the past or is present today, either below the surface or possibly in rare locations near small, hydrothermal vents like those we might find at Yellowstone. Our Mars missions have already sent back views of the Martian surface that seem to show evidence of dry riverbeds, flood plains, rare gullies on Martian cliffs and crater walls, and sedimentary deposits that suggest the presence of water at some point in the history of Mars.

Illustration of the Phoenix landing
Illustration of the Phoenix landing

The Phoenix will contribute to our overall picture of Mars. It will help us to determine if life ever arouse on Mars, and to understand its climate and geology. In addition it could also contribute to the preparations for human exploration.

_______________________________________________________
Further reading and source:
NASA - Phoenix Mars Lander

Dagbladet (Norwegian)

Tuesday, May 20, 2008

C++, Setting up your computer and writing your first program.

First of all we'll introduce some basic C++ terminology. It is important to learn good terminology in order to understand the concepts that we will be describing and discussing later on.

If you have been programming in other languages, you might have learned words like methods, functions and procedures. These are all named just "functions" in C++. A C++ program in its simplest form consist only of one function, which is called main. This is a pre-defined function name, and its body is enclosed in braces {}. The main function needs to exist so that your system (your run-time enviroment) will know where to start the execution of your program. If it didn't exist it would be like not knowing where to start reading a book. In order for your program to make sense, it needs a starting location – the main function.

When writing C++ code, you will be using some sort of text editor. If you are programming in a Windows enviroment, you could use a simple text editor like Notepad, Textpad or Notepad2. If you're in a linux enviroment you could use i.e. Notepad++, Pico or Nano. It really doesn't matter which editor you choose to use, as long as you give your source files the extension *.cpp. I.e. your first program could be named:

myFirstProgram.cpp

Let's say this file contains some code that you've written using Notepad. In order to make this file an actual program, we need to translate it into native machine code, a binary code consisting of only ones and zeros. Fortunately we don't do this manually. We have a program to do it for us – the compiler.

There are many C++ compilers out there, which perform pretty much the same (although they may vary slightly). It all boils down to this: You will have to make choice. Which editor will you be using? Which compiler will you be using? Tough questions? Well, don't worry. We will provide for you a complete and easy solution to these questions. This solution applies best to the Windows OS, because binaries only are availible to Windows systems. You can however compile the source code for your desired system. Well, anyway, the answer that we like, is Dev-C++ from Bloodshed. Dev-C++ is what we call an "IDE" (Integrated Development Enviroment). An IDE combines the editor, compiler and other useful tools in the same software package. There are of course alternatives, but Dev-C++ is under GNU General Public License which means it's free and open source (publicly availible source code), and it's also a very neat IDE.

The Dev-C++ workspace – a simple and nice GUI
The Dev-C++ workspace – a simple and nice GUI

Note: There might be other IDE alternatives that are better if you're an OS X or Linux user. If you want more information about this, just google it. I.e. "c++ IDE for linux", or simply post your question at our site.

For downloads and more information, please check out:
http://sourceforge.net/projects/dev-cpp/

After installing the IDE, we are ready to move on to our next section.

Writing your first program

Start up your IDE software, and create a new source file (a clean document). In Dev-C++ you can hit CTRL + N. This is where we'll type our code. So, let's get started.

Our program will be using commands for outputting and inputting information in a console window. To enable this functionality, we must include a library named iostream. Then we have to choose namespace to use, so the compiler will know what names are connected to our imported functionality. You don't need to fully understand at this point. The numbers to the left are line numbers.

1   #include <iostream>
2 using namespace std;

Next we have our main function, and the starting brace of our main function. As you can see the main function should return an integer value. When we return the value 0 (later in the code), our program will be terminated. This is considered good style, but it is not required by all compilers. Some compilers will allow your main method to return nothing thus writing void main( ), and some compilers doesn't even require a return statement, even if the function should return an integer. Well, anyway, we will use the following style, because it is good style.

3    int main( )
4 {

We are now inside the main function. The code that we write here will be executed line by line. So, let's declare a variable of type int, that we will name yourLuckyNumber. Btw: int is the C++ type for whole numbers; integers. Then we will use some of our imported functionality: cout (console output) and cin (console input). This is used for outputting and indputting information in the console window. Note that cout and cin used different operators (<< and >>). You will learn about operators later. Note: endl ends the current outputted line.

5        int yourLuckyNumber;

6 cout << "Please enter your lucky number, and hit enter: ";
7 cin >> yourLuckyNumber;
8 cout << endl;

Now that we have read an integer from the user, and stored this value in our variable, we can analyze this number so we can output appropriate information.

9        /* Determine whether your number is positive,    
10 negative or zero */

11 cout << "Your lucky number is ";

12 if (yourLuckyNumber == 0)
13 {
14 cout << "zero";
15 }
16 else if (yourLuckyNumber < 0)
17 {
18 cout << "negative";
19 }
20 else if (yourLuckyNumber > 0)
21 {
22 cout << "positive";
23 }

Line 9 and 10 are comments. By enclosing text within /* and */ you can provide information for yourself and the person that is reading your code. Comments will be skipped by the compiler and can be very useful when documenting the different parts of your program.

Now we will use an operator which is called modulo (in C++ this is represented by the percent symbol, %). The modulo function finds the remainder of division of one number by another. Given two numbers, a (the dividend) and n (the divisor), a % n is the remainder, on division of a by n. In example, the expression "7 % 3" would evaluate to 1, while "9 % 3" would evaluate to 0.

This function can be used to determine whether an integer is odd or even. If we have an integer, n, then the following expression will help us determine whether n is odd or even "n % 2". If the remainder is 0, then it is even (or zero), and if it's 1 that means our integer is an odd number.

24       cout << ", and it is also an ";

25 //Determine whether your number is an odd or even number
26 if (yourLuckyNumber % 2 == 0)
27 {
28 cout << "even number.";
29 }
30 else if (yourLuckyNumber % 2 != 0)
31 {
32 cout << "odd number.";
33 }

34 cout << endl;
35 cout << "That is all =)";
36 cout << endl;
37 system ("PAUSE");
38 return 0;
39 }

Notice line 25. Here we use a different style for our comment. In stead of enclosing some text within /* and */, we use // to make the rest of the line a comment, but only this line. If our comment uses more space than one line, we could put // in the beginning of each line, or we could enclose it with /* and */ as previously discussed.

Line 37 makes the console perform a pause. If we omit this line then our console window would open up, run, and then close again, giving us very little time to read the output of our program. Line 38 and 39 includes the return statement for the main function, and the closing brace for the main funciton.

You now have a complete C++ program which is ready to be compiled. If you are using Dev-C++ you can hit F9 (compile and run).

Here is the program running under Windows XP:
A sample run of our program
A sample run of our program (click for full size)