<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Coding Mix</title><link>http://www.codingmix.com/search/label/Cplusplus%20lessons</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/codingmix/Cplusplus/lessons" /><description></description><language>en</language><managingEditor>noreply@blogger.com (Csabi)</managingEditor><lastBuildDate>Thu, 23 Feb 2012 19:15:09 PST</lastBuildDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">9</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">25</openSearch:itemsPerPage><feedburner:info uri="codingmix/cplusplus/lessons" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>codingmix/Cplusplus/lessons</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>C++ Lesson 9 - Arrays</title><link>http://feedproxy.google.com/~r/codingmix/Cplusplus/lessons/~3/RqoY7CwOovA/cplusplus-lesson-9-arrays.html</link><category>Cplusplus lessons</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 03 Sep 2010 08:46:32 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-4106824301066022382</guid><description>Imagine a running competition with 5 runners. We want to store the seconds needed to finish the race for each runner. We would need 5 variables, one for each runner:&lt;div id="full-post"&gt;&lt;div class="code"&gt;int runner1 = 200;&lt;br /&gt;int runner2 = 105;&lt;br /&gt;int runner3 = 340;&lt;br /&gt;int runner4 = 243;&lt;br /&gt;int runner5 = 345;&lt;/div&gt;The disadvantage of the above code is that we can`t loop through the results. In this situation the best method is to use an &lt;b&gt;array&lt;/b&gt;.&lt;br /&gt;An array would look in the following way:&lt;div class="code"&gt;runner[0] = 200;&lt;br /&gt;runner[1] = 105;&lt;br /&gt;runner[2] = 340;&lt;br /&gt;runner[3] = 243;&lt;br /&gt;runner[4] = 345;&lt;/div&gt;&lt;br /&gt;Those numbers in the brackets are the &lt;b&gt;index&lt;/b&gt; number, and these numbers are showing the position of a given value in the array. &lt;br /&gt;&lt;b&gt;Initializing arrays&lt;/b&gt;&lt;br /&gt;An array can be initialized in three different ways:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;1.&lt;/b&gt; Syntax:&lt;div class="code"&gt;type identifier[max_elements_number];&lt;/div&gt;Example: &lt;div class="code"&gt;int runner[5];&lt;br /&gt;runner[0] = 200;&lt;br /&gt;runner[1] = 105;&lt;br /&gt;runner[2] = 340;&lt;br /&gt;runner[3] = 243;&lt;br /&gt;runner[4] = 345&lt;/div&gt; &lt;br /&gt;&lt;b&gt;2.&lt;/b&gt; Syntax:&lt;div class="code"&gt;type identifier[max_elements_number] = {element_1,element_2,element_max_elements_numbe};&lt;/div&gt;Example:&lt;div class="code"&gt;int runner[5] = {200,105,340,243,345};&lt;/div&gt;The number of elements can be fewer than the max_elements_number, but not greater.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;3.&lt;/b&gt; Syntax:&lt;div class="code"&gt;type identifier[] = {element_1,element_2,element_n};&lt;/div&gt;Example: &lt;div class="code"&gt;int runner[] = {200,105,340,243,345};&lt;/div&gt;The maximum number of elements is generated automatically based on the added elements number.&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;runner&lt;/i&gt; array look in the following way for the computer:&lt;div class="code"&gt;&lt;div style="float:left;"&gt;runner = &lt;/div&gt;&lt;table style="float:left;" width="200" border="1"&gt;&lt;tr&gt;&lt;td&gt;200&lt;/td&gt;&lt;td&gt;105&lt;/td&gt;&lt;td&gt;340&lt;/td&gt;&lt;td&gt;243&lt;/td&gt;&lt;td&gt;345&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;div style="float:left;width:520px;"&gt;                 (0)     (1)     (2)     (3)     (4)&lt;/div&gt;&lt;/div&gt;This is an &lt;b&gt;one-dimensional array&lt;/b&gt;, because it has only one index number. So, yes an array can have more than one index. Now you probably ask, why to use more than one indexes ?&lt;br /&gt;&lt;br /&gt;Well, let`s continue the idea of a running competition. Now imagine that you need to store the timings of the last 3 competitions for our 5 runners. The new array would look like this: &lt;div class="code"&gt;&lt;div style="float:left;"&gt;runner = &lt;/div&gt;&lt;table style="float:left;" width="200" border="1"&gt;&lt;tr&gt;&lt;td&gt;200&lt;/td&gt;&lt;td&gt;105&lt;/td&gt;&lt;td&gt;340&lt;/td&gt;&lt;td&gt;243&lt;/td&gt;&lt;td&gt;345&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;223&lt;/td&gt;&lt;td&gt;324&lt;/td&gt;&lt;td&gt;323&lt;/td&gt;&lt;td&gt;454&lt;/td&gt;&lt;td&gt;123&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;245&lt;/td&gt;&lt;td&gt;203&lt;/td&gt;&lt;td&gt;150&lt;/td&gt;&lt;td&gt;340&lt;/td&gt;&lt;td&gt;311&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;div style="float:left;line-height:27px;"&gt;(0)&lt;br /&gt;(1)&lt;br /&gt;(2)&lt;/div&gt;&lt;div style="float:left;width:520px;"&gt;                 (0)     (1)     (2)     (3)     (4)&lt;/div&gt;&lt;/div&gt;So we have 5 runners and a column for each of them. We have 3 competitions and a row for each of them. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Getting a value from this table&lt;/b&gt; &lt;br /&gt;Let`s say we need the timing of runner 2`s from the competition 1: &lt;div class="code"&gt;cout &lt;&lt; runner[2][1]; //323&lt;/div&gt; &lt;br /&gt;&lt;b&gt;Initializing a multi-dimensional array&lt;/b&gt;&lt;br /&gt;Because this is very similar to the one-dimensional arrays I will show you just some example:&lt;div class="code"&gt;int runner[5][3];&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;int runner[5][3] = {{200,223,245},{105,324,203},{340,323,150},{243,454,340},{345,123,311}};&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;int runner[][3] = {{200,223,245},{105,324,203},{340,323,150},{243,454,340},{345,123,311}};&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt;: With multi-dimensional arrays only the first index can be leaved blank!&lt;/div&gt;&lt;br /&gt;The max_elements_number needs to be a &lt;b&gt;constant&lt;/b&gt; value, this can`t be changed during the program runs. The first element of an array is always the 0th element.&lt;br /&gt;&lt;br /&gt;Here is an example of how useful can arrays be: &lt;div class="code"&gt;#include &lt;iostream&gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   int number[11];&lt;br /&gt;   for(int i=0;i&lt;=10;i++){&lt;br /&gt;      number[i] = i;&lt;br /&gt;   }&lt;br /&gt;   for(int i=0;i&lt;=10;i++){&lt;br /&gt;      cout &lt;&lt; number[i] &lt;&lt; endl;&lt;br /&gt;   }&lt;br /&gt;   system("pause");&lt;br /&gt;}&lt;/div&gt;The above program simply loads an array with numbers from 0 to 10 (11 elements) and then writes out the numbers. Using simple variables this would not be possible, we would need 11 variables and many lines of code for the same result.&lt;br /&gt;&lt;br /&gt;Next lesson: Coming soon&lt;br /&gt;Previous lesson: &lt;a href="http://www.codingmix.com/2010/07/cplusplus-lesson-8-while-loop-and-for.html"&gt;C++ Lesson 8 - while loop and for loop&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-4106824301066022382?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/C81oHxP7BNP6WagzcRIjqmJGBUg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/C81oHxP7BNP6WagzcRIjqmJGBUg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/C81oHxP7BNP6WagzcRIjqmJGBUg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/C81oHxP7BNP6WagzcRIjqmJGBUg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Cplusplus/lessons/~4/RqoY7CwOovA" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/09/cplusplus-lesson-9-arrays.html</feedburner:origLink></item><item><title>C++ Lesson 8 - while loop and for loop</title><link>http://feedproxy.google.com/~r/codingmix/Cplusplus/lessons/~3/2aKlCjilNfI/cplusplus-lesson-8-while-loop-and-for.html</link><category>Cplusplus lessons</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 03 Sep 2010 08:47:18 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-3225762893827518628</guid><description>Loops are used to execute a block of code multiple times, so you don`t have to write the same code again and again. Imagine how much time it would take to write a program what writes out the numbers from 1 to 1000 without using loops. In C++ are 3 types of loops:&lt;div id="full-post"&gt;&lt;br /&gt;&lt;b&gt;1. while&lt;/b&gt;&lt;br /&gt;The while loop executes a block of statements while a condition is true. The basic syntax of a while loop is:&lt;div class="code"&gt;while( condition ){&lt;br /&gt;   //code to execute while condition is true&lt;br /&gt;}&lt;/div&gt;Here is an example about how to use it. The following program will write out the numbers from 1 to 100: &lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   int i = 0;&lt;br /&gt;   while(i &amp;lt; 100){&lt;br /&gt;      cout &amp;lt;&amp;lt; ++i &amp;lt;&amp;lt; endl;&lt;br /&gt;   }&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;Before the while loop starts &lt;i&gt;i&lt;/i&gt; is declared with the value 0, but the first number will be 1, because the ++ is in front of &lt;i&gt;i&lt;/i&gt; (&lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-4-variables.html"&gt;Lesson 4&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;2. for&lt;/b&gt;&lt;br /&gt;The for loop is useful when you know how many times you need to repeat a block of code, because the for loop repeats the code for a specific number of times. The basic syntax is:&lt;div class="code"&gt;for(integer = starting value; integer &lt;= ending value; integer++){&lt;br /&gt;   //code to execute&lt;br /&gt;}&lt;/div&gt;We can use any variable name for the integer, but the default is &lt;i&gt;i&lt;/i&gt; or &lt;i&gt;y&lt;/i&gt;.&lt;br /&gt;Here is an example of using the for loop:&lt;br /&gt;Write out the numbers from 1 to 100:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   for(int i=1;i&amp;lt;=100;i++){&lt;br /&gt;      cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;br /&gt;   }&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;For the starting and ending value we can use variables, too. For example look at the bellow program which shows all the numbers between two numbers:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;Enter the starting number: &amp;quot;;&lt;br /&gt;   int startingnum;&lt;br /&gt;   cin &amp;gt;&amp;gt; startingnum;&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;Enter the ending number: &amp;quot;;&lt;br /&gt;   int endingnum;&lt;br /&gt;   cin &amp;gt;&amp;gt; endingnum;&lt;br /&gt;   for(startingnum;startingnum &amp;lt;= endingnum;startingnum++){&lt;br /&gt;      cout &amp;lt;&amp;lt; startingnum &amp;lt;&amp;lt; endl;&lt;br /&gt;   }&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;The counting expression can be anything, it can increment or decrement, or any mathematical expression, here are some examples:&lt;div class="code"&gt;for(int i=10;i&gt;0;i--)&lt;br /&gt;or&lt;br /&gt;for(int i=1;i&lt;=101;i+=10)&lt;br /&gt;or&lt;br /&gt;for(int i=1;i&lt;=101;i*=2)&lt;br /&gt;and so on....&lt;/div&gt;&lt;br /&gt;&lt;b&gt;3. do while&lt;/b&gt;&lt;br /&gt;The do while loop it`s similar to the while loop, the only difference is that the do while loop first executes the code and just after checks the condition, so the code inside the do while loop is executed at least once. &lt;br /&gt;&lt;br /&gt;The basic syntax is: &lt;div class="code"&gt;do{&lt;br /&gt;   //code to execute&lt;br /&gt;}while(condition);&lt;/div&gt;Here is and example of using the do while loop:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   int i = 0;&lt;br /&gt;   do{&lt;br /&gt;      cout &amp;lt;&amp;lt; ++i &amp;lt;&amp;lt; endl;&lt;br /&gt;   }while(i &amp;lt; 100);&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;The above program shows the numbers from 1 to 100. &lt;br /&gt;Next lesson: &lt;a href="http://www.codingmix.com/2010/09/cplusplus-lesson-9-arrays.html"&gt;C++ Lesson 9 - Arrays&lt;/a&gt;&lt;br /&gt;Previous lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-7-switchcase-statement.html"&gt;C++ Lesson 7 - switch/case statement&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-3225762893827518628?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/XlHIMepL5GakCUVLvDOwbNrgvvs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XlHIMepL5GakCUVLvDOwbNrgvvs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/XlHIMepL5GakCUVLvDOwbNrgvvs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XlHIMepL5GakCUVLvDOwbNrgvvs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Cplusplus/lessons/~4/2aKlCjilNfI" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">4</thr:total><feedburner:origLink>http://www.codingmix.com/2010/07/cplusplus-lesson-8-while-loop-and-for.html</feedburner:origLink></item><item><title>C++ Lesson 7 - switch/case statement</title><link>http://feedproxy.google.com/~r/codingmix/Cplusplus/lessons/~3/Dbu0gE-abm4/cplusplus-lesson-7-switchcase-statement.html</link><category>Cplusplus lessons</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Wed, 01 Sep 2010 07:07:14 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-4551401238672530239</guid><description>The switch/case statement usually it`s used to replace multiple if/else statements.&lt;br /&gt;The general syntax is:&lt;div id="full-post"&gt;&lt;div class="code"&gt;switch (variable){&lt;br /&gt;   case possible-value: &lt;br /&gt;      //code to execute&lt;br /&gt;      break;&lt;br /&gt;   default:&lt;br /&gt;      //code to execute&lt;br /&gt;}&lt;/div&gt;Now, let`s see it working: Let`s say that we want to write a program that will ask for a number between 1 and 5, and it will write out the number in text format (1 = one, 2 = two, 3 = three ....).&lt;br /&gt;Using the if/else if statements it will look like in the bellow example:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;Enter a number between 1 and 5!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;   int number;&lt;br /&gt;   cin &amp;gt;&amp;gt; number;&lt;br /&gt;   if(number == 1){&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;one&amp;quot;;&lt;br /&gt;   }&lt;br /&gt;   else if(number == 2){&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;two&amp;quot;;&lt;br /&gt;   }&lt;br /&gt;   else if(number == 3){&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;three&amp;quot;;&lt;br /&gt;   }&lt;br /&gt;   else if(number == 4){&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;four&amp;quot;;&lt;br /&gt;   }&lt;br /&gt;   else if(number == 5){&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;five&amp;quot;;&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      cout &amp;lt;&amp;lt; number &amp;lt;&amp;lt; &amp;quot; is not between 1 and 5!&amp;quot;;&lt;br /&gt;   }&lt;br /&gt;   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;And using the switch/case statement:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;Enter a number between 1 and 5!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;   int number;&lt;br /&gt;   cin &amp;gt;&amp;gt; number;&lt;br /&gt;   switch(number){&lt;br /&gt;   case 1: //if (number == 1)&lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;one&amp;quot;;&lt;br /&gt;      break;&lt;br /&gt;   case 2: //else if(number == 2) and so on... &lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;two&amp;quot;;&lt;br /&gt;      break;&lt;br /&gt;   case 3: &lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;three&amp;quot;;&lt;br /&gt;      break;&lt;br /&gt;   case 4: &lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;four&amp;quot;;&lt;br /&gt;      break;&lt;br /&gt;   case 5: &lt;br /&gt;      cout &amp;lt;&amp;lt; &amp;quot;five&amp;quot;;&lt;br /&gt;      break;&lt;br /&gt;   default: //if number is NOT 1,2,3,4 or 5&lt;br /&gt;      cout &amp;lt;&amp;lt; number &amp;lt;&amp;lt; &amp;quot; is not between 1 and 5!&amp;quot;;&lt;br /&gt;   }&lt;br /&gt;   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;&lt;b&gt;break;&lt;/b&gt;&lt;br /&gt;The break is used to break out from the switch/case statement. Without break the program will execute all the code after the selected one. For example, if we don`t use breaks in the above code, and the user inputs 3, the program will show:&lt;div class="code"&gt;threefourfive3 is not between 1 and 5!&lt;/div&gt;instead of &lt;div class="code"&gt;three&lt;/div&gt;Write the above code in your compiler and try it out to see it with your own eyes.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;default:&lt;/b&gt;&lt;br /&gt;The default case is optional, this is executed when none of the previous cases are executed or when you forget the break;.&lt;br /&gt;&lt;br /&gt;Note: The cases (including the default case) are followed by a colon, not semicolon!&lt;br /&gt;Note: &lt;b&gt;This is very important!&lt;/b&gt; A variable can`t be used as possible value of a case statement! Example of how NOT to do: &lt;div class="code"&gt;int myvariable = 1;&lt;br /&gt;switch (x){&lt;br /&gt;case myvariable: //this is NOT valid&lt;br /&gt;   //code to execute&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;&lt;b&gt;The same result for multiple values&lt;/b&gt;&lt;br /&gt;If you want to execute the same code in more cases, you don`t have to write that code multiple times, just write it like in the bellow example:&lt;div class="code"&gt;switch (myvariable){&lt;br /&gt;case 1:&lt;br /&gt;case 2:&lt;br /&gt;case 3:&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;myvariable is 1,2 or 3&amp;quot;;&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;Recommended project: Write a calculator program, first ask for a number, then let the user to select from a list of mathematic operations (*,/,+,-), than ask for a second number and than write out the result using switch/case statement when possible. Pay attention to every possibility, you don`t want to have a program that crashes all the time.&lt;br /&gt;&lt;br /&gt;Here is a link to a tutorial about how to make it, but before reading it try to solve it! Coming soon.&lt;br /&gt;&lt;br /&gt;Next lesson: &lt;a href="http://www.codingmix.com/2010/07/cplusplus-lesson-8-while-loop-and-for.html"&gt;C++ Lesson 8 - while loop and for loop&lt;/a&gt;&lt;br /&gt;Previous lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-6-ifelseelse-if_18.html"&gt;C++ Lesson 6 - if/else/else if statements&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-4551401238672530239?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/XUT_4EW-0vjYEcx4qBLrYSUl6m8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XUT_4EW-0vjYEcx4qBLrYSUl6m8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/XUT_4EW-0vjYEcx4qBLrYSUl6m8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XUT_4EW-0vjYEcx4qBLrYSUl6m8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Cplusplus/lessons/~4/Dbu0gE-abm4" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total><feedburner:origLink>http://www.codingmix.com/2010/06/cplusplus-lesson-7-switchcase-statement.html</feedburner:origLink></item><item><title>C++ Lesson 6 - if/else/else if statements</title><link>http://feedproxy.google.com/~r/codingmix/Cplusplus/lessons/~3/n-XghPRr_tk/cplusplus-lesson-6-ifelseelse-if_18.html</link><category>Cplusplus lessons</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Wed, 01 Sep 2010 07:08:57 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-3820134802452056242</guid><description>The &lt;b&gt;if, else&lt;/b&gt; and &lt;b&gt;else if&lt;/b&gt; statements are used to decide what code to execute based on different conditions. The program makes decisions based on whether a given condition is true or false. Condition can be a boolean or the comparison of two values. The C++ comparison operators are:&lt;div id="full-post"&gt;&lt;table style="width:545px;"&gt;&lt;tr style="background:#33bb33; color:white;"&gt;&lt;td&gt;Operator&lt;/td&gt;&lt;td&gt;Description&lt;/td&gt;&lt;td&gt;Example (&lt;b&gt;x = 2&lt;/b&gt;)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;==&lt;/td&gt;&lt;td&gt;Equal to&lt;/td&gt;&lt;td&gt;x == 3 is false&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;!=&lt;/td&gt;&lt;td&gt;Not equal to&lt;/td&gt;&lt;td&gt;x != 3 is true&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&amp;gt;&lt;/td&gt;&lt;td&gt;Greater than&lt;/td&gt;&lt;td&gt;x &amp;gt; 2 is false&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&amp;lt;&lt;/td&gt;&lt;td&gt;Less than&lt;/td&gt;&lt;td&gt;x &amp;lt; 2 is true&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&amp;gt;=&lt;/td&gt;&lt;td&gt;Greater than or equal to&lt;/td&gt;&lt;td&gt;x &amp;gt;= 2 is true&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&amp;lt;=&lt;/td&gt;&lt;td&gt;Less than or equal to&lt;/td&gt;&lt;td&gt;x &amp;lt;= 2 is true&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;b&gt;if&lt;/b&gt;&lt;br /&gt;General syntax: &lt;div class="code"&gt;if( condition ) {&lt;br /&gt;   //code to execute if condition is true&lt;br /&gt;}&lt;/div&gt;Here is an example: &lt;div class="code"&gt;int x=5;&lt;br /&gt;if(x == 5){&lt;br /&gt;   cout &amp;lt;&amp;lt; "x is equal to 5"; //this message will be shown only if x = 5&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;&lt;b&gt;else&lt;/b&gt;&lt;br /&gt;General syntax: &lt;div class="code"&gt;if( condition ) {&lt;br /&gt;   //code to execute if condition is true&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   //code to execute if condition is false&lt;br /&gt;}&lt;/div&gt;Here is an example:&lt;div class="code"&gt;int x;&lt;br /&gt;cin &amp;gt;&amp;gt; x;&lt;br /&gt;if(x &lt; 5){&lt;br /&gt;   cout &amp;lt;&amp;lt; "x is less than 5";&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   cout &amp;lt;&amp;lt; "x is greater or equal to 5";&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;&lt;b&gt;else if&lt;/b&gt;&lt;br /&gt;This is used when we want to check more then two possibilities. General syntax:&lt;div class="code"&gt;if( condition1 ){&lt;br /&gt;   //code to execute if condition1 is true&lt;br /&gt;}&lt;br /&gt;else if( condition2 ){&lt;br /&gt;   //code to execute if condition1 is false and condition2 is true&lt;br /&gt;}&lt;/div&gt;Here is an example:&lt;div class="code"&gt;int x;&lt;br /&gt;cin &amp;gt;&amp;gt; x;&lt;br /&gt;if(x &lt; 5){&lt;br /&gt;   cout &amp;lt;&amp;lt; "x is less than 5";&lt;br /&gt;}&lt;br /&gt;else if(x &gt; 5){&lt;br /&gt;   cout &amp;lt;&amp;lt; "x is greater than 5";&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   cout &amp;lt;&amp;lt; "x is equal to 5";&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Using a boolean&lt;/b&gt;&lt;br /&gt;Here is an example: &lt;div class="code"&gt;bool x = true;&lt;br /&gt;if(x){&lt;br /&gt;   cout &amp;lt;&amp;lt; "x is true";&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Using logical operators&lt;/b&gt;&lt;br /&gt;The logical operators in C++ are:&lt;div class="code"&gt;!        inverse&lt;br /&gt;&amp;&amp;    and&lt;br /&gt;||        or&lt;/div&gt;&lt;br /&gt;!&lt;br /&gt;The ! logical operator inverts the value of a boolean operation. Example:&lt;div class="code"&gt;bool x = false;&lt;br /&gt;if(!x){ //this checks if the inverted value of x is true or not&lt;br /&gt;   cout &amp;lt;&amp;lt; "x is false";  //!x is true and x is false&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;&amp;&amp;&lt;br /&gt;This logical operator is used when we want to execute a code only if more than one conditions are true. Example:&lt;div class="code"&gt;bool x = true;&lt;br /&gt;bool y = true;&lt;br /&gt;if(x &amp;&amp; y){&lt;br /&gt;   cout &amp;lt;&amp;lt; "both of them are true";&lt;br /&gt;}&lt;br /&gt;y = false;&lt;br /&gt;if(x &amp;&amp; y){&lt;br /&gt;   //this code &lt;b&gt;won`t&lt;/b&gt; be executed because not all the condition are true&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;||&lt;br /&gt;This logical operator is used when we want to execute a code when at least one of the conditions is true. Examples:&lt;div class="code"&gt;bool x = true;&lt;br /&gt;bool y = true;&lt;br /&gt;if(x || y){&lt;br /&gt;   //code will be executed because all the conditions are true&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;x = false;&lt;br /&gt;if(x || y){&lt;br /&gt;   //code will be executed because at least one of the conditions are true&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;y = false;&lt;br /&gt;if(x || y){&lt;br /&gt;   //code won`t be executed because none of the conditions are true.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Note: You can use as many times you want the &amp;&amp; and || operators.&lt;/div&gt;&lt;br /&gt;The best way to learn programming is by practicing!&lt;br /&gt;Recommended project: Write a calculator program, first ask for a number, then  let the user to select from a list of mathematic operations (*,/,+,-), than ask for a second number and than write out the result. Pay attention to every possibility, you don`t want to have a program that crashes all the time.&lt;br /&gt;&lt;br /&gt;If you fail at first don`t give up try it again. If you can`t solve this after several tries here you can find my tutorial about how to make it: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-console-calculator-v1.html"&gt;Calculator v1&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Next lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-7-switchcase-statement.html"&gt;C++ Lesson 7 - switch/case statement&lt;/a&gt;&lt;br /&gt;Previous lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-5-inputoutput.html"&gt;C++ Lesson 5 - Input/Output&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-3820134802452056242?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gW9CMp65HK5mFe7A4sxxfL3FdRg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gW9CMp65HK5mFe7A4sxxfL3FdRg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gW9CMp65HK5mFe7A4sxxfL3FdRg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gW9CMp65HK5mFe7A4sxxfL3FdRg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Cplusplus/lessons/~4/n-XghPRr_tk" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/06/cplusplus-lesson-6-ifelseelse-if_18.html</feedburner:origLink></item><item><title>C++ Lesson 5 - Input/Output</title><link>http://feedproxy.google.com/~r/codingmix/Cplusplus/lessons/~3/myZUyzDMaO8/cplusplus-lesson-5-inputoutput.html</link><category>Cplusplus lessons</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Wed, 01 Sep 2010 07:09:33 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-4094648943764639542</guid><description>Think, how useful is a program that gives the same result at all or a program that can`t even show the result. Well, I wouldn't pay for a such program. This is the reson why in this lesson I will write more about writing out syntax and about how to create a program that can interact with the user.&lt;br /&gt;&lt;div id="full-post"&gt;&lt;br /&gt;To output something we will use &lt;b&gt;cout&lt;/b&gt;, to input something we will use &lt;b&gt;cin&lt;/b&gt;. These are predefined stream objects. These are declared in the &amp;lt;iostream&amp;gt; library (header file), so in order to use cout or cin we need to include it. iostream stands for &lt;b&gt;I&lt;/b&gt;nput/&lt;b&gt;O&lt;/b&gt;utput &lt;b&gt;Stream&lt;/b&gt;. A stream is a sequence of data of undetermined length (for example: when an user inputs something the computer don`t know what he will type in).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;cout&lt;/b&gt;&lt;br /&gt;cout is used to write out something. The name stands from &lt;b&gt;c&lt;/b&gt;++ &lt;b&gt;out&lt;/b&gt;. This needs to be used with the &lt;&lt; operator. The &lt;&lt; operator inserts the data flow into the stream. You can use multiple times the &lt;&lt; operator:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   int myvariable = 15;&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;I`m &amp;quot; &amp;lt;&amp;lt; myvariable &amp;lt;&amp;lt; &amp;quot; years old&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;The above program will output something like this:&lt;div class="code"&gt;I`m 15 years old&lt;br /&gt;Press any key to continue ...&lt;/div&gt;&lt;br /&gt;Note: The semicolon (;) need to be placed only once at the end of the line.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;cin&lt;/b&gt;&lt;br /&gt;cin is used to read what the user inputs. The names stands for &lt;b&gt;c&lt;/b&gt;++ &lt;b&gt;in&lt;/b&gt;. This needs to be used with the &gt;&gt; operator. The &gt;&gt; operator reads the data from the stream (stream loads the data inputed from the keyboard). The &gt;&gt; operator can be used multiple times too, but usually we will use a single &gt;&gt; operator because the program is more useful if the user know what he needs to input. Here is an example:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   int age;&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;What`s your age ?&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;   cin &amp;gt;&amp;gt; age;&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;You are &amp;quot; &amp;lt;&amp;lt; age &amp;lt;&amp;lt; &amp;quot; years old.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;The above program will output something like this (depending on what you will input):&lt;div class="code"&gt;What`s your age ?&lt;br /&gt;15&lt;br /&gt;You are 15 years old.&lt;br /&gt;Press any key to continue ...&lt;/div&gt;&lt;br /&gt;Next lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-6-ifelseelse-if_18.html"&gt;C++ Lesson 6 - if/else/else if statements&lt;/a&gt;&lt;br /&gt;Previous lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-4-variables.html"&gt;C++ Lesson 4 - Variables&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-4094648943764639542?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/n-YwGrm0MEh6kKxH3-fHfbyAsv4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/n-YwGrm0MEh6kKxH3-fHfbyAsv4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/n-YwGrm0MEh6kKxH3-fHfbyAsv4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/n-YwGrm0MEh6kKxH3-fHfbyAsv4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Cplusplus/lessons/~4/myZUyzDMaO8" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/06/cplusplus-lesson-5-inputoutput.html</feedburner:origLink></item><item><title>C++ Lesson 4 - Variables</title><link>http://feedproxy.google.com/~r/codingmix/Cplusplus/lessons/~3/Tc6KAkPhqYM/cplusplus-lesson-4-variables.html</link><category>Cplusplus lessons</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Wed, 01 Sep 2010 07:10:01 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-2798748566903162870</guid><description>What is a variable ? A variable is a facility to store data. We can store values in variables and we can change it`s value. In C++ we can use multiple variable types, but the following ones are the most used:&lt;div class="code"&gt;&lt;b&gt;int&lt;/b&gt; - An integer number&lt;br /&gt;&lt;b&gt;bool&lt;/b&gt; - Boolean, it can be only True or False&lt;br /&gt;&lt;b&gt;float&lt;/b&gt; - Floating point number&lt;br /&gt;&lt;b&gt;double&lt;/b&gt; - Double precision floating point number&lt;br /&gt;&lt;b&gt;char&lt;/b&gt; - A single character&lt;br /&gt;&lt;b&gt;string&lt;/b&gt; - String of text&lt;/div&gt;&lt;div id="full-post"&gt;Before using a variable, it needs to be initialized. The syntax is:&lt;div class="code"&gt;type identifier;&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;type identifier = value;&lt;/div&gt;In this lesson we will talk only about integer, these are the easiest to work with. Here is an example of initializing an integer without and with an initial value. I will call the variable &lt;b&gt;myvariable&lt;/b&gt;:&lt;div class="code"&gt;int myvariable; //without initial value&lt;br /&gt;&lt;br /&gt;int myvariable = 5; //the initial value is 5&lt;/div&gt;As I said the value of the variables can be changed using operators. The basic operators in C++ are: + , - , * , / , % , = , += , -= , *= , /= , %= , and here is a long list of examples:&lt;div class="code"&gt;int myvariable;   // intializing without initial value&lt;br /&gt;myvariable = 5 + 2;   // 7&lt;br /&gt;myvariable = myvariable - 4;   //3&lt;br /&gt;myvariable = 6 * myvariable;   //18&lt;br /&gt;myvariable = myvariable / 3;   //6&lt;br /&gt;myvariable = myvariable % 4;   //2 (division remainder)&lt;br /&gt;myvariable = 10;   //10&lt;br /&gt;myvariable += 2;   //12&lt;br /&gt;myvariable -= 8;   //4&lt;br /&gt;myvariable *= 2;   //8&lt;br /&gt;myvariable /= 2;   //4&lt;br /&gt;myvariable %= 3;   //1&lt;/div&gt;To write out the value of a variable just leave the double quotes from the cout line:&lt;div class="code"&gt;cout &lt;&lt; myvariable;&lt;/div&gt;, but we will talk more about cout in the next lesson. Here is an example program that uses integer variables:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;int main(){&lt;br /&gt;   int myvariable;   // intializing without initial value&lt;br /&gt;   myvariable = 5 + 2;   //7&lt;br /&gt;   myvariable = myvariable - 4;   //3&lt;br /&gt;   myvariable = 6 * myvariable;   //18&lt;br /&gt;   myvariable = myvariable / 3;   //6&lt;br /&gt;   myvariable = myvariable % 4;   //2 (division remainder)&lt;br /&gt;   myvariable = 10;   //10&lt;br /&gt;   myvariable += 2;   //12&lt;br /&gt;   myvariable -= 8;   //4&lt;br /&gt;   myvariable *= 2;   //8&lt;br /&gt;   myvariable /= 2;   //4&lt;br /&gt;   myvariable %= 3;   //1&lt;br /&gt;   cout &amp;lt;&amp;lt; myvariable &amp;lt;&amp;lt; endl; &lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;The above program should write out 1. Play with the code, remove and add new lines to familiarize with integers.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Increment and Decrement&lt;/b&gt;&lt;br /&gt;Using the incrementing (++) or decrementing (--) operators means to add or to subtract 1 from the value of an &lt;b&gt;integer&lt;/b&gt; variable. These operators can be used in two ways:&lt;div class="code"&gt;++number; //the value is increased &lt;b&gt;before&lt;/b&gt; the value is used in the rest of the expression&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;number++ //the value is increased &lt;b&gt;after&lt;/b&gt; the value is used in the rest of the expression&lt;/div&gt;For example try out the following code:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   int numberone = 2;&lt;br /&gt;   int numbertwo = 2;&lt;br /&gt;   cout &amp;lt;&amp;lt; ++numberone &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; numbertwo++ &amp;lt;&amp;lt; endl;&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;As you probably noticed the two written values are not the same. The first is 3, because the value is increased before it`s written and the second value is 2,because it`s increased only after it`s written.&lt;br /&gt;Note: The increment and decrement operators are working only with integers!&lt;br /&gt;&lt;br /&gt;&lt;b&gt;float&lt;/b&gt; and &lt;b&gt;double&lt;/b&gt;&lt;br /&gt;Float and double are working exactly like integers, but these can be floating point numbers, too (2.75 or 9.24323). The difference between float and double is that a double can have more numbers after the decimal point then a float. Initializing a float or a double should look like in the bellow example:&lt;div class="code"&gt;float myvariable;&lt;br /&gt;or&lt;br /&gt;float myvariable = 4.23;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Making the result of integer division a float&lt;/b&gt;&lt;br /&gt;Try out to give the value of dividing two integers to a float. The result will don`t have floating point any numbers you use. To solve this look at my example:&lt;br /&gt;&lt;div class="code"&gt;int numone = 1;&lt;br /&gt;int numtwo = 2;&lt;br /&gt;float result = (float) numone / numtwo;&lt;/div&gt;Try out the above example, it should work.&lt;br /&gt;&lt;div class="code"&gt;&lt;br /&gt;double myvariable;&lt;br /&gt;or&lt;br /&gt;double myvariable = 5.24;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Booleans&lt;/b&gt;&lt;br /&gt;Booleans can have only two values: &lt;b&gt;true(1)&lt;/b&gt; or &lt;b&gt;false(0)&lt;/b&gt;. Initializing a boolean should look like in the bellow example:&lt;div class="code"&gt;bool myvariable = true;&lt;br /&gt;or&lt;br /&gt;bool myvariable = false;&lt;/div&gt;Note: In C++ a and A are not equal. Be careful, &lt;b&gt;don`t&lt;/b&gt; use uppercase letters to write true or false. This is true for the name of the variables, too. For example: myvariable and Myvariable are two different variables.&lt;br /&gt;&lt;br /&gt;Next lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-5-inputoutput.html"&gt;C++ Lesson 5 - Input/Output&lt;/a&gt;&lt;br /&gt;Previous lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-3-hello-world.html"&gt;C++ Lesson 3 - Hello world&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-2798748566903162870?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZD1jPP74ycgX4LKqnJRR7zEHoYs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZD1jPP74ycgX4LKqnJRR7zEHoYs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZD1jPP74ycgX4LKqnJRR7zEHoYs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZD1jPP74ycgX4LKqnJRR7zEHoYs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Cplusplus/lessons/~4/Tc6KAkPhqYM" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/06/cplusplus-lesson-4-variables.html</feedburner:origLink></item><item><title>C++ Lesson 3 - Hello world</title><link>http://feedproxy.google.com/~r/codingmix/Cplusplus/lessons/~3/RRucSVCPiIw/cplusplus-lesson-3-hello-world.html</link><category>Cplusplus lessons</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 03 Sep 2010 03:02:34 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-5544442831280551715</guid><description>In this lesson I will show you how to create a simple program, called Hello world, which will simply just write out "Hello world!". A Hello world program is the best way to start in programming language, because this gives a basic understand of the syntax of the code.&lt;br /&gt;&lt;br /&gt;First set up an empty Win32 Console Application project and add a C++ file (main.cpp) like in &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-set-up-visual.html"&gt;lesson 2&lt;/a&gt;.&lt;br /&gt;&lt;div id="full-post"&gt;&lt;br /&gt;Write the following code and press F5 to run it:&lt;div class="code"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;   cout &amp;lt;&amp;lt; &amp;quot;Hello world!&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;   system(&amp;quot;pause&amp;quot;);&lt;br /&gt;}&lt;/div&gt;The first line includes the &lt;b&gt;iostream&lt;/b&gt; library which provides the input and output functions. Without this function we can`t write out the result of the program. Notice that wen a library is included &lt;b&gt;#include&lt;/b&gt; is used.&lt;br /&gt;&lt;br /&gt;The second line tell the compiler to use the &lt;b&gt;std&lt;/b&gt; namespace, namespace allows to create groups of functions or objects under a name. Don`t worry, I will write more about namespace later. For now it`s good to know that if you leave this line from the code you will need to include std:: before each cout or cin from your code. Notice that the line is ended by a semicolon (";");&lt;br /&gt;&lt;br /&gt;The third line starts a function called main, which will return and int (integer). The main function starts first in any program. The curly braces { and } shows the beginning and end of the function.&lt;br /&gt;&lt;br /&gt;The next line writes out the "Hello world!" text. Notice that the line is ended by a semicolon (";").&lt;br /&gt;&lt;br /&gt;The next line is telling the compiler to pause the program and wait for the user to press Enter. Without &lt;b&gt;system("pause")&lt;/b&gt; the program will run so fast that you will not see the result. &lt;br /&gt;&lt;br /&gt;Let`s see the program in action:&lt;a href="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TBTQYne-xnI/AAAAAAAAAPk/DngW-SXPnvU/s1600/Hello+world.jpg"&gt;&lt;img style="display:block; margin:5px auto 5px; text-align:center;width: 541px; height: 273px;" src="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TBTQYne-xnI/AAAAAAAAAPk/DngW-SXPnvU/s1600/Hello+world.jpg" border="0" alt="Hello world example"id="BLOGGER_PHOTO_ID_5482235767751100018" /&gt;&lt;/a&gt;Note: Don`t worry if you haven`t understand everything. This lesson is written to have an idea about how a program looks and to see the basic syntax of C++. &lt;br /&gt;&lt;br /&gt;Another useful and simple thing to learn are comments: In C++ you can add comments (notes) after the code lines. The comments are skipped by the compiler and they don`t affect the program. Comment are helpful to note or explain things. The comment syntax is:&lt;div class="code"&gt;//Comment goes here&lt;/div&gt;or&lt;div class="code"&gt;/*Comment line 1&lt;br /&gt;Comment line 2 */&lt;/div&gt;&lt;br /&gt;Next lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-4-variables.html"&gt;C++ Lesson 4 - Variables&lt;/a&gt;&lt;br /&gt;Previous lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-set-up-visual.html"&gt;C++ Lesson 2 - Set up Visual C++&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-5544442831280551715?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3yrgnR2BolozWPDTFArIhl0AMp4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3yrgnR2BolozWPDTFArIhl0AMp4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3yrgnR2BolozWPDTFArIhl0AMp4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3yrgnR2BolozWPDTFArIhl0AMp4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Cplusplus/lessons/~4/RRucSVCPiIw" height="1" width="1"/&gt;</description><media:thumbnail url="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TBTQYne-xnI/AAAAAAAAAPk/DngW-SXPnvU/s72-c/Hello+world.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.codingmix.com/2010/06/cplusplus-lesson-3-hello-world.html</feedburner:origLink></item><item><title>C++ Lesson 2 - Set up Visual C++</title><link>http://feedproxy.google.com/~r/codingmix/Cplusplus/lessons/~3/1mnYlHgm5xU/cplusplus-lesson-set-up-visual.html</link><category>Cplusplus lessons</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Wed, 01 Sep 2010 07:10:29 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-8448597953122743886</guid><description>This lesson is about setting up Visual C++ for a console application. Console applications are the easiest C++ program so this is the best way to start.&lt;br /&gt;&lt;br /&gt;First it`s good to create a folder for your projects (anywhere you want), then go to:&lt;br /&gt;&lt;b&gt;File &gt;&gt; New &gt;&gt; Project...&lt;/b&gt; and select &lt;b&gt;Win32 Console Application:&lt;/b&gt;&lt;div id="full-post"&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TBH6sREgkSI/AAAAAAAAAO8/iJuy_yiWYhA/s1600/Set+up+visual+c%2B%2B.jpg"&gt;&lt;img style="display:block; margin:5px auto 5px; text-align:center; width: 545px; height: 377px;" src="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TBH6sREgkSI/AAAAAAAAAO8/iJuy_yiWYhA/s1600/Set+up+visual+c%2B%2B.jpg" border="0" alt="Set up Visual C++"id="BLOGGER_PHOTO_ID_5481437859890106658" /&gt;&lt;/a&gt;At the bottom give a name for your project, same as the solution name. At the location browse and select your projects folder to place the new project in.&lt;br /&gt;&lt;br /&gt;Then click &lt;b&gt;Ok&lt;/b&gt;, then &lt;b&gt;next&lt;/b&gt; (NOT finish), and check in the &lt;b&gt;Empty project&lt;/b&gt; checkbox:&lt;a href="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TBINVKk-paI/AAAAAAAAAPE/dRBp7aGaWbk/s1600/Set+up+visual+c%2B%2B+project.jpg"&gt;&lt;img style="display:block; margin:5px auto 5px; text-align:center;cursor:pointer; cursor:hand;width: 545px; height: 461px;" src="http://3.bp.blogspot.com/_Ok7mVUxPcsk/TBINVKk-paI/AAAAAAAAAPE/dRBp7aGaWbk/s1600/Set+up+visual+c%2B%2B+project.jpg" border="0" alt="Set up Visual C++"id="BLOGGER_PHOTO_ID_5481458353731184034" /&gt;&lt;/a&gt;Then on the &lt;b&gt;Solution Explorer&lt;/b&gt; (at the left side) right click on &lt;b&gt;Source Files&lt;/b&gt; and select &lt;b&gt;Add &gt;&gt; New Item...&lt;/b&gt;&lt;a href="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TBIqCTBnSHI/AAAAAAAAAPM/Q3TKGwupghE/s1600/Set+up+visual+c%2B%2B+project+2.jpg"&gt;&lt;img style="display:block; margin:5px auto 5px; text-align:center;width: 529px; height: 338px;" src="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TBIqCTBnSHI/AAAAAAAAAPM/Q3TKGwupghE/s1600/Set+up+visual+c%2B%2B+project+2.jpg" border="0" alt="Set up Visual C++ console"id="BLOGGER_PHOTO_ID_5481489915418462322" /&gt;&lt;/a&gt;Select &lt;b&gt;C++ File (.cpp)&lt;/b&gt;, name it whatever you want (I will call it &lt;b&gt;main&lt;/b&gt;) , then click &lt;b&gt;Add&lt;/b&gt;&lt;a  href="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TBJfbDRQzhI/AAAAAAAAAPU/zPBfa_VCgN8/s1600/Set+up+visual+c%2B%2B+project+3.jpg"&gt;&lt;img style="display:block; margin:5px auto 5px; text-align:center;width: 545px; height: 377px;" src="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TBJfbDRQzhI/AAAAAAAAAPU/zPBfa_VCgN8/s1600/Set+up+visual+c%2B%2B+project+3.jpg" border="0" alt="C++ Set up add item"id="BLOGGER_PHOTO_ID_5481548614802132498" /&gt;&lt;/a&gt;And this is it, now just expand the &lt;b&gt;Source Files&lt;/b&gt; folder and double click on your file (what I`we called &lt;b&gt;main&lt;/b&gt;) and start coding !&lt;a href="http://4.bp.blogspot.com/_Ok7mVUxPcsk/TBJ6zMkr6aI/AAAAAAAAAPc/_1bSmZB92zE/s1600/Set+up+visual+c%2B%2B+project+4.jpg"&gt;&lt;img style="display:block; margin:5px auto 5px; text-align:center;width: 545px; height: 448px;" src="http://4.bp.blogspot.com/_Ok7mVUxPcsk/TBJ6zMkr6aI/AAAAAAAAAPc/_1bSmZB92zE/s1600/Set+up+visual+c%2B%2B+project+4.jpg" border="0" alt="Setting up Visual c++ ready"id="BLOGGER_PHOTO_ID_5481578716430330274" /&gt;&lt;/a&gt;Don`t forget to save your project (go to &lt;b&gt;File &gt;&gt; Save all&lt;/b&gt; or press &lt;b&gt;Ctrl + Shift + S&lt;/b&gt;).&lt;br /&gt;To debug and start your program press &lt;b&gt;F5&lt;/b&gt;, for sure when you will write one.&lt;br /&gt;&lt;br /&gt;Check out my video about this lesson: &lt;a href="http://www.youtube.com/watch?v=suaQxj3nnMc"&gt;How to set up Visual C++ for a Console Application&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Next lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-3-hello-world.html"&gt;C++ Lesson 3 - Hello world&lt;/a&gt;&lt;br /&gt;Previous lesson: &lt;a href="http://www.codingmix.com/2010/06/introducing-to-cplusplus-lesson-1.html"&gt;C++ Lesson 1 - Introducing&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-8448597953122743886?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/HNYpJ6ttyf-eTFXNKKsAIRBKw4U/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HNYpJ6ttyf-eTFXNKKsAIRBKw4U/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/HNYpJ6ttyf-eTFXNKKsAIRBKw4U/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/HNYpJ6ttyf-eTFXNKKsAIRBKw4U/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Cplusplus/lessons/~4/1mnYlHgm5xU" height="1" width="1"/&gt;</description><media:thumbnail url="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TBH6sREgkSI/AAAAAAAAAO8/iJuy_yiWYhA/s72-c/Set+up+visual+c%2B%2B.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://www.codingmix.com/2010/06/cplusplus-lesson-set-up-visual.html</feedburner:origLink></item><item><title>C++ Lesson 1 - Introducing</title><link>http://feedproxy.google.com/~r/codingmix/Cplusplus/lessons/~3/QdqKOnUeYek/introducing-to-cplusplus-lesson-1.html</link><category>Cplusplus lessons</category><category>Cplusplus</category><author>noreply@blogger.com (Csabi)</author><pubDate>Wed, 01 Sep 2010 07:10:41 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6030285891847709676</guid><description>First let`s talk about programming. What programming really means? Programming means to write the source-code of a program. The source code is the human-readable part of a program. When a program is running it tell the computer what to do, but the computer don`t understands human languages. This is the reason why we need a Compiler. A compiler is a program what translates the human-readable code to machine code what is understood by the computer. &lt;br /&gt;&lt;div id="full-post"&gt;&lt;br /&gt;You probably think that the computer is very wise, but it`s not. The computer it`s able only to follow simple instructions. In the following lessons we will learn about giving some basic instruction to the computer using C++. C++ is a very powerful programming language, many of the newest and best games are made in C++.&lt;br /&gt;&lt;br /&gt;Ok, now that you know what means to program you are just one step from starting to program. As I mentioned above, the human-readable code must be translated to machine code. To translate the code we need a compiler. You can choose from many compiler, but I will choose Visual C++ Express from Microsoft. Visual C++ 2010 can be download for free from &lt;a href="http://www.microsoft.com/express/Downloads"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;It`s easy to install it and I think that somebody who wants to program knows how to install a simple program or a game. Note: Download only the Visual C++ Express, we will use only this one.&lt;br /&gt;&lt;br /&gt;In the following lesson you will see lots of example codes and downloadable source-codes at each lesson, but don`t just copy it, try to write it on yourself (multiple times if you think), because the best way to learn programming is practicing.&lt;br /&gt;&lt;br /&gt;Next lesson: &lt;a href="http://www.codingmix.com/2010/06/cplusplus-lesson-set-up-visual.html"&gt;C++ Lesson 2 - Set up Visual C++&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6030285891847709676?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZIR3jT2-gU5lOoRyRJbMqQrU_9A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZIR3jT2-gU5lOoRyRJbMqQrU_9A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZIR3jT2-gU5lOoRyRJbMqQrU_9A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZIR3jT2-gU5lOoRyRJbMqQrU_9A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/Cplusplus/lessons/~4/QdqKOnUeYek" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">3</thr:total><feedburner:origLink>http://www.codingmix.com/2010/06/introducing-to-cplusplus-lesson-1.html</feedburner:origLink></item><media:rating>nonadult</media:rating></channel></rss>

