<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-2677128750081523261</atom:id><lastBuildDate>Sat, 21 Feb 2009 09:08:57 +0000</lastBuildDate><title>C++ Tutorials</title><description></description><link>http://ngsfuse.blogspot.com/</link><managingEditor>noreply@blogger.com (Fuse)</managingEditor><generator>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-2677128750081523261.post-5503278396911731321</guid><pubDate>Wed, 26 Mar 2008 08:09:00 +0000</pubDate><atom:updated>2008-03-26T01:13:03.942-07:00</atom:updated><title></title><description>&lt;div class="google_header" id="google_header"&gt;   &lt;p id="eiag"&gt;         &lt;/p&gt; &lt;/div&gt; &lt;div id="pmq." style="text-align: center;"&gt;&lt;font id="oj38" color="#999999"&gt;&lt;font id="d4e5" size="4"&gt;&lt;font id="kc30" color="#333333"&gt;&lt;b id="rz0l"&gt;User Input and Variables&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;br id="ft0e"&gt;  &lt;/div&gt;&lt;div id="ox._"&gt;   &lt;div id="vbvn" style="text-align: center;"&gt;     &lt;font id="k3_v" size="4"&gt;&lt;font id="wu:b" size="1"&gt;&lt;i id="qm1c"&gt;Made by Fuse and Phial&lt;/i&gt;&lt;/font&gt;&lt;/font&gt;&lt;br id="lk65"&gt;   &lt;/div&gt;   &lt;div id="dad0" style="text-align: center;"&gt;     ★&lt;font id="ryt6" size="4"&gt;&lt;font id="h5mo" size="1"&gt;&lt;i id="kclp"&gt;I like shrimpies.&lt;/i&gt;&lt;/font&gt;&lt;/font&gt;★&lt;br id="s3bn"&gt;   &lt;/div&gt;   &lt;br id="z9ct"&gt;   &lt;div id="o0p4" style="text-align: center;"&gt;     &lt;font id="u0_2" size="4"&gt;&lt;font id="b3ze" size="1"&gt;&lt;b id="jsvp"&gt;&lt;i id="f:87"&gt; Promoted Sites:&lt;br id="ns.:"&gt;     &lt;a href="http://nextgenscene.net" id="f7js" title="www.NextGenScene.net"&gt;www.NextGenScene.net&lt;/a&gt;&lt;br id="lkac"&gt;     &lt;/i&gt;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;   &lt;/div&gt;   &lt;br id="s7ys"&gt;   &lt;br id="j5ww"&gt;   &lt;br id="a3od"&gt;   &lt;b id="ipl3"&gt;&lt;u id="a2tt"&gt;What are Variables?:&lt;/u&gt;&lt;/b&gt;&lt;br id="gb2v"&gt;        &lt;div id="jn2w"&gt;       &lt;div id="zee2" style="margin-left: 40px;"&gt;         Variables store data in the computers memory kinda like we store numbers in our head. If I told you to remember the number 5 and then I told you to remember the number 16 you have just stored those two numbers in your memory. And if I told you to add the number 3 to the first number you should be able to come up with the number 8. Variables work just like that, in fact the same process can be done in c++ like this&lt;br id="dq.s"&gt;         &lt;br id="it2_"&gt;         &lt;font id="bndr" face="Courier New"&gt;a = 5;&lt;/font&gt;&lt;br id="axsu"&gt;&lt;font id="bndr" face="Courier New"&gt;         b = 16;&lt;/font&gt;&lt;br id="a7u_"&gt;&lt;font id="bndr" face="Courier New"&gt;         c = a + b;&lt;/font&gt;&lt;br id="psen"&gt;         &lt;/div&gt;&lt;/div&gt;&lt;div id="x01g" style="margin-left: 40px;"&gt;&lt;div id="jn2w"&gt;&lt;div id="zee2" style="margin-left: 40px;"&gt;         &lt;div id="y74r"&gt;         &lt;/div&gt;         &lt;br id="yugb"&gt;       &lt;/div&gt;       &lt;/div&gt;&lt;/div&gt;&lt;div id="x01g"&gt;&lt;div id="jn2w"&gt;&lt;div id="aqyz"&gt;         &lt;b id="tfgg"&gt;&lt;u id="fxav"&gt;How to Declare a Variable:&lt;/u&gt;&lt;/b&gt;&lt;br id="mqsr"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="x01g"&gt;&lt;div id="jn2w"&gt;&lt;div id="aqyz"&gt;             To declare a variable you first start with its type, followed by the name and a semicolon.  You can also initialize a variable when you create it.  This is done exactly the same way as creating a variable but the name is followed by and equals sign and the value.&lt;br id="o07k"&gt;         &lt;br id="r7hl" style="font-style: italic;"&gt;&lt;font id="p9hc" size="1"&gt;         &lt;i id="ukpz"&gt;     The following example creates two integer variables.&lt;/i&gt;&lt;/font&gt;&lt;br id="bdx3" style="font-family: Courier New;"&gt;         &lt;span id="nv4o" style="font-family: Courier New;"&gt;            int aVariable;&lt;/span&gt;&lt;br id="pro0" style="font-family: Courier New;"&gt;         &lt;span id="r.5m" style="font-family: Courier New;"&gt;            int anotherVariable = 10;&lt;/span&gt;&lt;br id="fr6h" style="font-family: Courier New;"&gt;         &lt;br id="wegw"&gt;             In the example &lt;span id="wfm1" style="font-family: Courier New;"&gt;aVariable&lt;/span&gt; is created as an integer type.  This means that it can only hold an integer value. Since &lt;span id="vaba" style="font-family: Courier New;"&gt;aVariable&lt;/span&gt; is not initialized it could hold any value at the moment.  This could cause some strange outputs if you forget to initialize it before you use it.  To solve this problem we create &lt;span id="nnua" style="font-family: Courier New;"&gt;anotherVariable&lt;/span&gt; and initialize it to 10.  Now we can use it and know what value it holds.  Initializing variables is good programming practice, and it reduces the headaches of debugging strange outputs.&lt;br id="djwf"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div id="x01g" style="margin-left: 40px;"&gt;&lt;div id="jn2w"&gt;&lt;div id="aqyz"&gt;         &lt;br id="dfy4" style="font-weight: bold;"&gt;         &lt;font id="y5q3" size="1"&gt;&lt;b id="lx5v"&gt;&lt;i id="nj7f"&gt; Listing 1.1&lt;/i&gt;&lt;/b&gt;&lt;/font&gt;&lt;br id="ej:y"&gt;         &lt;div id="w:h7"&gt;           &lt;table id="dq2_" bgcolor="#cccccc" border="0" cellpadding="3" cellspacing="0" height="250" width="621"&gt;             &lt;tbody id="lh51"&gt;             &lt;tr id="dcdt"&gt;               &lt;td id="vmmp" width="100%"&gt;                 &lt;font id="j-3h" size="2"&gt;&lt;span id="ow9o" style="font-family: Courier New;"&gt;//Demonstrates using variables and Initializing variables&lt;br id="ei49"&gt;                 #include &amp;lt;iostream&amp;gt;&lt;br id="j-qy"&gt;                 using namespace std;&lt;br id="gjt8"&gt;                 &lt;br id="trqc"&gt;                 int main()&lt;br id="q22h"&gt;                 {&lt;br id="lqur"&gt;                 int aVariable;&lt;br id="s977"&gt;                 int anotherVariable = 10;  //Initializing a value to anotherVariable&lt;br id="a1sz"&gt;                 &lt;br id="hl1j"&gt;                 aVariable = 0;  //Assigning a value to a variable&lt;br id="sqzj"&gt;                 &lt;br id="h3wt"&gt;                 cout &amp;lt;&amp;lt; "aVariable: " &amp;lt;&amp;lt; aVariable &amp;lt;&amp;lt; endl;&lt;br id="wr_."&gt;                 cout &amp;lt;&amp;lt; "anotherVariable: " &amp;lt;&amp;lt; anotherVariable &amp;lt;&amp;lt; endl;&lt;br id="xa7n"&gt;                 &lt;br id="cx80"&gt;                 system("Pause");&lt;br id="s-3e"&gt;                 &lt;br id="hav6"&gt;                 return 0;&lt;br id="wsyb"&gt;                 }&lt;/span&gt;&lt;/font&gt;&lt;br id="exrj"&gt;               &lt;/td&gt;             &lt;/tr&gt;             &lt;/tbody&gt;           &lt;/table&gt;           &lt;br id="s-08"&gt;         &lt;/div&gt;         &lt;div id="qlxl" style="margin-left: 40px;"&gt;           &lt;b id="uu10"&gt;Output:&lt;/b&gt;&lt;br id="apf5"&gt;           aVariable: 0&lt;br id="k.0v"&gt;           anotherVariable: 10&lt;br id="z0g7"&gt;         &lt;/div&gt;         &lt;br id="jmjk"&gt;         &lt;br id="k1t4"&gt;         &lt;u id="o24v"&gt;&lt;b id="wk42"&gt;Data Types:&lt;br id="l_.k"&gt;         &lt;/b&gt;&lt;/u&gt;    At this point we have only gone over one example of a data type called an integer, lets go over some other data types in detail.&lt;br id="bfem"&gt;         &lt;font id="y5q3" size="1"&gt;&lt;b id="lx5v"&gt;&lt;i id="nj7f"&gt; Listing 1.2&lt;/i&gt;&lt;/b&gt;&lt;/font&gt;&lt;br id="t_43"&gt;         &lt;div id="c6t1"&gt;           &lt;table id="ll8u" bgcolor="#cccccc" border="0" cellpadding="3" cellspacing="0" height="258" width="749"&gt;             &lt;tbody id="b_2x"&gt;             &lt;tr id="w5ed"&gt;               &lt;td id="pqd2" style="text-align: center;" width="25%"&gt;&lt;b&gt;                 Name&lt;br id="l1.-"&gt;               &lt;/b&gt;&lt;/td&gt;               &lt;td id="l1ny" style="text-align: center;" width="25%"&gt;&lt;b&gt;                 Description&lt;br id="wlpx"&gt;               &lt;/b&gt;&lt;/td&gt;               &lt;td id="j1hn" style="text-align: center;" width="25%"&gt;&lt;b&gt;                 Size&lt;br id="fopz"&gt;               &lt;/b&gt;&lt;/td&gt;               &lt;td id="v2wz" style="text-align: center;" width="25%"&gt;&lt;b&gt;                 Range&lt;br id="dfgc"&gt;               &lt;/b&gt;&lt;/td&gt;             &lt;/tr&gt;             &lt;tr id="q_s6" bgcolor="#ffffff"&gt;               &lt;td id="o:_o" width="25%"&gt;                 char&lt;br id="zuom"&gt;               &lt;/td&gt;               &lt;td id="l1rm" width="25%"&gt;                 Character or small integer.&lt;br id="tzy5"&gt;               &lt;/td&gt;               &lt;td id="lqrq" width="25%"&gt;                 1 byte&lt;br id="nanh"&gt;               &lt;/td&gt;               &lt;td id="cdd8" width="25%"&gt;                 signed: -128 to 127&lt;br id="buow"&gt;                 unsigned: 0 to 255               &lt;/td&gt;             &lt;/tr&gt;             &lt;tr id="pgp6" bgcolor="#cccccc"&gt;               &lt;td id="hk7j" width="25%"&gt;                 short int&lt;br id="xfp4"&gt;               &lt;/td&gt;               &lt;td id="id4." width="25%"&gt;                 Short integer&lt;br id="opnk"&gt;               &lt;/td&gt;               &lt;td id="mdz8" width="25%"&gt;                 2 bytes&lt;br id="q1-e"&gt;               &lt;/td&gt;               &lt;td id="sbht" width="25%"&gt;                 signed: -32768 to 32767&lt;br id="geba"&gt;                 unsigned: 0 to 65535               &lt;/td&gt;             &lt;/tr&gt;             &lt;tr id="he62" bgcolor="#ffffff"&gt;               &lt;td id="wf6r" width="25%"&gt;                 int&lt;br id="x_eu"&gt;               &lt;/td&gt;               &lt;td id="nca7" width="25%"&gt;                 Integer&lt;br id="r0yf"&gt;               &lt;/td&gt;               &lt;td id="tbb0" width="25%"&gt;                 4 bytes&lt;br id="mxxa"&gt;               &lt;/td&gt;               &lt;td id="xhjg" width="25%"&gt;                 signed: -2147483648 to 2147483647&lt;br id="cfug"&gt;                 unsigned: 0 to 4294967295               &lt;/td&gt;             &lt;/tr&gt;             &lt;tr id="zxrt"&gt;               &lt;td id="qnbu" width="25%"&gt;                 long int&lt;br id="t9pb"&gt;               &lt;/td&gt;               &lt;td id="sjs3" width="25%"&gt;                 Long integer&lt;br id="a7-r"&gt;               &lt;/td&gt;               &lt;td id="q_yx" width="25%"&gt;                 4 bytes&lt;br id="t7:w"&gt;               &lt;/td&gt;               &lt;td id="ylx4" width="25%"&gt;                 signed: -2147483648 to 2147483647&lt;br id="ek4t"&gt;                 unsigned: 0 to 4294967295&lt;br id="z5_0"&gt;               &lt;/td&gt;             &lt;/tr&gt;             &lt;tr id="lhuh" bgcolor="#ffffff"&gt;               &lt;td id="le24" width="25%"&gt;                 bool&lt;br id="vhzv"&gt;               &lt;/td&gt;               &lt;td id="f3hd" width="25%"&gt;                 Boolean value. Takes one of two values, true or false.&lt;br id="bph8"&gt;               &lt;/td&gt;               &lt;td id="w2se" width="25%"&gt;                 1 byte&lt;br id="v3e-"&gt;               &lt;/td&gt;               &lt;td id="vr.5" width="25%"&gt;                 True or False&lt;br id="coun"&gt;               &lt;/td&gt;             &lt;/tr&gt;             &lt;tr id="h1zn"&gt;               &lt;td id="l4.p" width="25%"&gt;                 float&lt;br id="f98r"&gt;               &lt;/td&gt;               &lt;td id="p_tv" width="25%"&gt;                 Floating point number&lt;br id="es4p"&gt;               &lt;/td&gt;               &lt;td id="y7g-" width="25%"&gt;                 4 bytes&lt;br id="qak8"&gt;               &lt;/td&gt;               &lt;td id="iqzy" width="25%"&gt;                 3.4e +/- 38 (7 digits)               &lt;/td&gt;             &lt;/tr&gt;             &lt;tr id="ztpq" bgcolor="#ffffff"&gt;               &lt;td id="ys.t" width="25%"&gt;                 double&lt;br id="mo4v"&gt;               &lt;/td&gt;               &lt;td id="dl5o" width="25%"&gt;                 Double precision floating point number.&lt;br id="s8ma"&gt;               &lt;/td&gt;               &lt;td id="ma5a" width="25%"&gt;                 8 bytes&lt;br id="w_lc"&gt;               &lt;/td&gt;               &lt;td id="fqal" width="25%"&gt;                 1.7e +/- 308 (15 digits)               &lt;/td&gt;             &lt;/tr&gt;             &lt;tr id="cdpk"&gt;               &lt;td id="wnay" width="25%"&gt;                 long double&lt;br id="gh3o"&gt;               &lt;/td&gt;               &lt;td id="c:3-" width="25%"&gt;                 Long double precision floating point number.               &lt;/td&gt;               &lt;td id="s-yt" width="25%"&gt;                 8 bytes&lt;br id="pabb"&gt;               &lt;/td&gt;               &lt;td id="px8e" width="25%"&gt;                 1.7e +/- 308 (15 digits)               &lt;/td&gt;             &lt;/tr&gt;             &lt;tr id="gcfu" bgcolor="#ffffff"&gt;               &lt;td id="m40n" width="25%"&gt;                 wchar_t&lt;br id="bu.v"&gt;               &lt;/td&gt;               &lt;td id="r2-f" width="25%"&gt;                 Wide character&lt;br id="ym-k"&gt;               &lt;/td&gt;               &lt;td id="z61r" width="25%"&gt;                 2 bytes&lt;br id="k59x"&gt;               &lt;/td&gt;               &lt;td id="qrtg" width="25%"&gt;                 1 wide character               &lt;/td&gt;             &lt;/tr&gt;             &lt;/tbody&gt;           &lt;/table&gt;           &lt;br id="apln"&gt;           You might be looking at this going what the hell am i looking at, I'm going to explain the best way i can think of, and that is with a example program.&lt;br id="iseu"&gt;           &lt;font id="y5q3" size="1"&gt;&lt;b id="lx5v"&gt;&lt;i id="nj7f"&gt; Listing 1.3&lt;/i&gt;&lt;/b&gt;&lt;/font&gt;&lt;br id="yg-8"&gt;           &lt;div id="u5-."&gt;             &lt;table id="y9rm" bgcolor="#cccccc" border="0" cellpadding="3" cellspacing="0" height="308" width="605"&gt;               &lt;tbody id="ag8v"&gt;               &lt;tr id="u2wk"&gt;                 &lt;td id="w_6j" width="100%"&gt;                   &lt;span id="kgiq" style="font-family: Courier New;"&gt; //Demonstrates the sizes of different data types&lt;/span&gt;&lt;br id="zqxf" style="font-family: Courier New;"&gt;                   &lt;span id="aoxy" style="font-family: Courier New;"&gt; #include &amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;br id="kbkd" style="font-family: Courier New;"&gt;                   &lt;br id="e7xb" style="font-family: Courier New;"&gt;                   &lt;span id="pup4" style="font-family: Courier New;"&gt; using namespace std;&lt;/span&gt;&lt;br id="wf52" style="font-family: Courier New;"&gt;                   &lt;br id="pimz" style="font-family: Courier New;"&gt;                   &lt;span id="ff.-" style="font-family: Courier New;"&gt; int main()&lt;/span&gt;&lt;br id="sw42" style="font-family: Courier New;"&gt;                   &lt;span id="bbn:" style="font-family: Courier New;"&gt; {&lt;/span&gt;&lt;br id="bc4p" style="font-family: Courier New;"&gt;                   &lt;span id="wwbr" style="font-family: Courier New;"&gt;     //Some values may differ depending on your system.&lt;/span&gt;&lt;br id="w0_0" style="font-family: Courier New;"&gt;                   &lt;span id="mn_g" style="font-family: Courier New;"&gt;     cout &amp;lt;&amp;lt; "size of int: " &amp;lt;&amp;lt; sizeof(int) &amp;lt;&amp;lt; " bytesn";&lt;/span&gt;&lt;br id="czc:" style="font-family: Courier New;"&gt;                   &lt;span id="u97v" style="font-family: Courier New;"&gt;     cout &amp;lt;&amp;lt; "size of short int: " &amp;lt;&amp;lt; sizeof(short int) &amp;lt;&amp;lt; " bytesn";&lt;/span&gt;&lt;br id="bn70" style="font-family: Courier New;"&gt;                   &lt;span id="yrt-" style="font-family: Courier New;"&gt;     cout &amp;lt;&amp;lt; "size of long int: " &amp;lt;&amp;lt; sizeof(long int) &amp;lt;&amp;lt; " bytesn";&lt;/span&gt;&lt;br id="j1ol" style="font-family: Courier New;"&gt;                   &lt;span id="hpp9" style="font-family: Courier New;"&gt;     cout &amp;lt;&amp;lt; "size of double: " &amp;lt;&amp;lt; sizeof(double) &amp;lt;&amp;lt; " bytesn";&lt;/span&gt;&lt;br id="et82" style="font-family: Courier New;"&gt;                   &lt;span id="vei7" style="font-family: Courier New;"&gt;     cout &amp;lt;&amp;lt; "size of float: " &amp;lt;&amp;lt; sizeof(float) &amp;lt;&amp;lt; " bytesn";&lt;/span&gt;&lt;br id="nv_y" style="font-family: Courier New;"&gt;                   &lt;span id="yqrb" style="font-family: Courier New;"&gt;     cout &amp;lt;&amp;lt; "size of bool: " &amp;lt;&amp;lt; sizeof(bool) &amp;lt;&amp;lt; " bytesn";&lt;/span&gt;&lt;br id="gj:u" style="font-family: Courier New;"&gt;                   &lt;span id="oj7b" style="font-family: Courier New;"&gt;     cout &amp;lt;&amp;lt; "size of char: " &amp;lt;&amp;lt; sizeof(char) &amp;lt;&amp;lt; " bytesn";&lt;/span&gt;&lt;br id="nf0m" style="font-family: Courier New;"&gt;                     &lt;span id="u-84" style="font-family: Courier New;"&gt;&lt;br id="e.yx"&gt;                       system("Pause");&lt;br id="bsa4"&gt;                   &lt;br id="p_-l" style="font-family: Courier New;"&gt;                   &lt;/span&gt; &lt;span id="anu4" style="font-family: Courier New;"&gt;     return 0;&lt;br id="i8:p" style="font-family: Courier New;"&gt;                   &lt;/span&gt; &lt;span id="fx3e" style="font-family: Courier New;"&gt; }&lt;/span&gt;&lt;br id="ivsi"&gt;                 &lt;/td&gt;               &lt;/tr&gt;               &lt;/tbody&gt;             &lt;/table&gt;           &lt;/div&gt;           &lt;br id="qp_y"&gt;         &lt;/div&gt;         &lt;div id="yjsk" style="margin-left: 40px;"&gt;           &lt;b id="musb"&gt; Output:&lt;/b&gt;&lt;br id="rgsm"&gt;           size of int: 4 bytes&lt;br id="x1t0"&gt;           size of short int: 2 bytes&lt;br id="xy1h"&gt;           size of long int: 4 bytes&lt;br id="qt.r"&gt;           size of double: 8 bytes&lt;br id="dg5z"&gt;           size of float: 4 bytes&lt;br id="o3or"&gt;           size of bool: 1 bytes&lt;br id="i6ni"&gt;           size of char: 1 bytes&lt;br id="mev6"&gt;         &lt;/div&gt;       &lt;/div&gt;     &lt;/div&gt;   &lt;/div&gt;   &lt;br id="v5.e"&gt;   &lt;br id="yagv"&gt; &lt;/div&gt; &lt;div id="pr9i"&gt;   &lt;b id="f6lf"&gt;&lt;u id="x:vf"&gt;What is User Input?:&lt;/u&gt;&lt;/b&gt;&lt;br id="zllh"&gt;       User input is a way of letting a user interact with your application, whether that is by using a keyboard, mouse, or other input device.  Letting users interact with your application by inputting values of their choice increases the usability of the program.  The keyboard is the most commonly used device for input into an application, and so that is what we will cover here.&lt;br id="cwek"&gt;   In later lessons you will learn how to read input from a file.  You will quickly learn that letting users input values of their choice opens up a whole new world of problems, from wrong type of input, to too much input.  Later we will cover how to protect yourself against these bad inputs.&lt;br id="b5.y"&gt;         &lt;p class="MsoNormal" id="oj3h"&gt;          Input via the keyboard is stored in an input stream.  Data is stored here for you to act upon how you want.  To read in a value from the stream you first specify the input stream you want access to, followed by the extraction operator, and finally the variable to store the value in.   &lt;/p&gt;   &lt;p class="MsoNormal" id="oj3h"&gt;     &lt;font id="gvgk" size="2"&gt;&lt;span id="ay.0" style="font-family: Courier New;"&gt;cin &amp;gt;&amp;gt; aInt;&lt;/span&gt;&lt;/font&gt;   &lt;/p&gt;   &lt;p class="MsoNormal" id="oj3h"&gt;     &lt;font id="gvgk" size="2"&gt;&lt;span id="ay.0" style="font-family: Courier New;"&gt;&lt;font id="nwkq" face="Verdana"&gt;You may be wondering what cin is.  It's a stream object that is connected to keyboard input, it is automatically defined for you in the std namespace.  A source of confusion for some beginners is the extraction operator (&amp;gt;&amp;gt;).  It looks similar to the insertion operator (&amp;lt;&amp;lt;) so to help you remember which direction to point your arrows try to remember this:&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;   &lt;/p&gt;   &lt;p class="MsoNormal" id="oj3h"&gt;     &lt;span id="zbpe" style="font-family: Courier New;"&gt;cout &amp;lt;&amp;lt; "Hi"; // &amp;lt;&amp;lt; its pointing out, used for output&lt;/span&gt;&lt;br id="l0:-" style="font-family: Courier New;"&gt;   &lt;/p&gt;   &lt;p class="MsoNormal" id="oj3h" style="font-family: Courier New;"&gt;     cin &amp;gt;&amp;gt; aInt; // &amp;gt;&amp;gt; its pointing in, used for input.   &lt;/p&gt;   &lt;p class="MsoNormal" id="oj3h"&gt;     &lt;br id="jkw8"&gt;   &lt;/p&gt;   &lt;br id="f7q1" style="font-weight: bold; text-decoration: underline;"&gt;   &lt;span id="pzv9"&gt;&lt;span id="xzng"&gt;&lt;b&gt;&lt;u&gt;Storing User Input in Variables:&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br id="rp:i"&gt;   &lt;/span&gt;   To store user input to a variable you will need to first declare the variable and its data type, and then ask the user for input like shown below.&lt;br id="rs2:"&gt;   &lt;font id="y5q3" size="1"&gt;&lt;b id="lx5v"&gt;&lt;i id="nj7f"&gt; Listing 2.1&lt;/i&gt;&lt;/b&gt;&lt;/font&gt;&lt;br id="eb7c"&gt;   &lt;div id="z-wh"&gt;     &lt;table id="rmag" bgcolor="#cccccc" border="0" cellpadding="3" cellspacing="0" height="26" width="648"&gt;       &lt;tbody id="lpsq"&gt;       &lt;tr id="o_16"&gt;         &lt;td id="fsx3" width="100%"&gt;           #include &amp;lt;iostream&amp;gt;&lt;br id="axdh"&gt;           &lt;br id="tzji"&gt;           using namespace std;&lt;br id="ehai"&gt;           &lt;br id="n7la"&gt;           int main()&lt;br id="qg1h"&gt;           {&lt;br id="d5gf"&gt;             &lt;br id="hgy8"&gt;              // Declare the variables that you are going to be working with.&lt;br id="jyny"&gt;              int a;&lt;br id="jmd7"&gt;              int b;&lt;br id="g9xo"&gt;           &lt;div id="s2bd" style="margin-left: 40px;"&gt;&lt;br id="v1ok"&gt;&lt;/div&gt;              // Ask for the user's input.&lt;br id="gxdg"&gt;              cout &amp;lt;&amp;lt; "Please enter a number: " &amp;lt;&amp;lt; endl;&lt;br id="x_mf"&gt;              cin &amp;gt;&amp;gt; a;&lt;br id="mu8h"&gt;           &lt;br id="k.bs"&gt;              cout &amp;lt;&amp;lt; "Please enter another number: " &amp;lt;&amp;lt; endl;&lt;br id="y0c2"&gt;              cin &amp;gt;&amp;gt; b;&lt;br id="wwuj"&gt;           &lt;br id="s7iw"&gt;              cout &amp;lt;&amp;lt; "The value you entered for a is: " &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl;&lt;br id="b7en"&gt;              cout &amp;lt;&amp;lt; "The value you entered for b is: " &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl;&lt;br id="coii"&gt;           &lt;br id="brcg"&gt;           system("Pause");&lt;br id="xsjh"&gt;           return 0;&lt;br id="mrxg"&gt;           }&lt;br id="hhmz"&gt;         &lt;/td&gt;       &lt;/tr&gt;       &lt;/tbody&gt;     &lt;/table&gt;   &lt;/div&gt;   &lt;br id="yye7"&gt;   &lt;div id="jspv" style="margin-left: 40px;"&gt;     &lt;b id="musb"&gt; Output:&lt;/b&gt;&lt;br id="rgsm"&gt;     The value you entered for a is: 5&lt;br id="x1t0"&gt;     The value you entered for b is: 3&lt;br id="f7eh"&gt;     &lt;br id="tmn2"&gt;   &lt;/div&gt;   &lt;u id="n0qg"&gt;&lt;b id="lrzm"&gt;Lesson Review:&lt;/b&gt;&lt;/u&gt;&lt;br id="qz_j"&gt;       What you learned in this lesson:&lt;br id="llav"&gt;   &lt;ul id="v.3k"&gt;     &lt;li id="zmu9"&gt;       What a variable is.     &lt;/li&gt;     &lt;li id="u9nh"&gt;       The many types of variables available.     &lt;/li&gt;     &lt;li id="u9nh"&gt;       How to declare, initialize, and store a value in a variable.     &lt;/li&gt;     &lt;li id="u9nh"&gt;       What user input is.     &lt;/li&gt;     &lt;li id="u9nh"&gt;       How to extract input from a user and store it in a variable.&lt;br id="ue:u"&gt;     &lt;/li&gt;   &lt;/ul&gt;         &lt;br id="i361"&gt;   &lt;br id="xy.g"&gt;   &lt;u id="egf5"&gt;&lt;b id="b6e6"&gt;Practice Exercise:&lt;/b&gt;&lt;/u&gt;&lt;br id="zck8"&gt;   &lt;div id="jspv" style="margin-left: 40px;"&gt;   &lt;/div&gt;       Make a program that asks the user for their birthday and displays it back to them.&lt;br id="kl7v"&gt;       &lt;font id="cz5o" size="1"&gt;&lt;span id="evyh"&gt;&lt;b&gt;Sample output.&lt;/b&gt;&lt;/span&gt;&lt;/font&gt;&lt;br id="ua4y"&gt;       What is your birthday?&lt;br id="yx9k"&gt;       Enter the month: 8&lt;br id="nrzn"&gt;       Enter the day: 21&lt;br id="lpth"&gt;       Enter the year: 1988&lt;br id="g9-o"&gt;       Your birthday is 8/21/1988.&lt;br id="uebk"&gt;   &lt;br id="zqib"&gt;   &lt;div id="jwi_" style="margin-left: 40px;"&gt;   &lt;/div&gt;   &lt;div id="o:n." style="text-align: left;"&gt;   &lt;/div&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2677128750081523261-5503278396911731321?l=ngsfuse.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ngsfuse.blogspot.com/2008/03/user-input-and-variables-made-by-fuse.html</link><author>noreply@blogger.com (Fuse)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-2677128750081523261.post-6423317602151419718</guid><pubDate>Sun, 20 Jan 2008 23:29:00 +0000</pubDate><atom:updated>2008-01-25T12:48:30.046-08:00</atom:updated><title></title><description>                                                                                                                                                                                                                                    &lt;h1 style="text-align: center; font-family: Verdana;"&gt;&lt;font color="#666666" size="5"&gt;&lt;b&gt;Intro To C++!&lt;/b&gt;&lt;/font&gt;&lt;/h1&gt;&lt;h1 style="text-align: center; font-family: Verdana;"&gt;&lt;font size="1"&gt;Tutorials created by Fuse&lt;/font&gt;&lt;br&gt;&lt;/h1&gt;&lt;div style="text-align: center;"&gt;Promoted Sites:&lt;br&gt;&lt;a title="www.NextGenBoards.com" target="_blank" href="http://nextgenboards.com" id="f68."&gt;www.NextGenBoards.com&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;font color="#660000"&gt;&lt;font size="4"&gt;Tools used for this tutorial-&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;ul&gt;&lt;li&gt;&lt;a title="Visual Studio 2008 Express (Free!)" target="_blank" href="http://www.microsoft.com/express/download/default.aspx" id="g6pe"&gt;Visual Studio 2008 Express (Free!)&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;&lt;u&gt;Tutorial Introduction-&lt;br&gt;&lt;/u&gt;&lt;/b&gt;&lt;div style="margin-left: 40px;"&gt;&lt;br&gt;I will be writing a series of c++ tutorials over the next few months. I am going to teach the basics (console programming) to the more advanced (including winapi, and directx). I have been studying c++ on and off for about 4 years now, recently i have been reading allot of directx tutorials and I'm planning on completing my series of c++ tutorials with a complete directory of tutorials with everything you need to know to make a full direct3d game. I'm hoping to add some 3d modeling and game audio tutorials as well but that will come after the programming tutorials. Hopefully i can get this whole project done within 6 months, its definitely possible. I hope you enjoy and take in what i am trying to teach, it will take allot of dedication and practise to be able to program on your own two feet, but i will try to make learning the c++ language as easy as possible. Lets get started. If you have not already, download Visual Studio 2008 Express, i have provided a link above. &lt;br&gt;&lt;br&gt;After downloading install the program to its default directory. &lt;br&gt;&lt;br&gt;When installation is complete, open up Visual C++ 2008 Express. If you have any problems installing or downloading just post a comment and i will reply asap.&lt;font size="2"&gt;&lt;br&gt;&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;b&gt;&lt;u&gt;Making a new project in visual C++:&lt;/u&gt;&lt;/b&gt; &lt;br&gt;&lt;br&gt;&lt;div style="margin-left: 40px;"&gt;If you have been following along visual c++ should already be open, if not go ahead and open it. To make a new project go to File&amp;gt;New&amp;gt;Project. The new project window will open, we need to make a "Win32 Console Application" so make sure you click it. Before we can move on we need to name our project, for the sake of this tutorial we will call it helloworld.&lt;br&gt;&lt;br&gt;&lt;div id="l9aw" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img style="width: 500px; height: 400px;" src="http://docs.google.com/File?id=dc24prf_3c9qx93cf"&gt;&lt;br&gt;&lt;br&gt;Click OK, then click next. In the application settings under application type click the bubble for "Console Application". Then under the "Additional Options" check the "Empty project" box.&lt;br&gt;&lt;br&gt;&lt;div id="mqm5" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img style="width: 500px; height: 400px;" src="http://docs.google.com/File?id=dc24prf_4gg5mc7hk"&gt;&lt;br&gt;&lt;br&gt;This will be the default settings that you will use to make a console application, go ahead and click finish.&lt;br&gt;&lt;br&gt;We only have one more step before we are done setting up the project, we need to add a source file to our project. To do this Right click on the source files folder then click add&amp;gt;new item. The source files folder can be found under the solution explorer which is located on the left side of the screen. If you do not see it hold down Ctrl+Alt+L to open it up.&lt;br&gt;&lt;br&gt;&lt;div id="ssqp" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img style="width: 500px; height: 400px;" src="http://docs.google.com/File?id=dc24prf_53vtdf5cg"&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;The "Add New Item" window will pop up, we need to add a new C++ Source File (.cpp file) so click the C++ Source File and then name your source file, you can name it whatever you want, i went ahead and named mine hellosource.&lt;br&gt;&lt;br&gt;&lt;div id="bbp_" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img style="width: 500px; height: 400px;" src="http://docs.google.com/File?id=dc24prf_6fq8h59gz"&gt;&lt;br&gt;&lt;br&gt;Click add, you will probably notice that a new tab has opened up named hellosource.cpp that contains a editor, this is where we will program our actual console application.&lt;br&gt;&lt;br&gt;&lt;div id="hjkz" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img style="width: 500px; height: 400px;" src="http://docs.google.com/File?id=dc24prf_7cn8fhkhf"&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;We are now ready to start programming!&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br style="font-weight: bold; text-decoration: underline;"&gt;&lt;br style="font-weight: bold; text-decoration: underline;"&gt;&lt;br style="font-weight: bold; text-decoration: underline;"&gt;&lt;b&gt;&lt;u&gt;Your First Program!:&lt;br&gt;&lt;/u&gt;&lt;/b&gt;At this point you are probably wondering what a console application is. Ill try to explain it as simple as i can, a console application is a computer program designed to be used via a text-only computer interface. Dos is a type of console application. Lets go ahead and get started on some programming! Im going to go ahead and type out the source code, and explain each part in detail afterwards.&lt;br&gt;&lt;br&gt;&lt;blockquote&gt;//Include the iostream standard file&lt;br&gt;#include &amp;lt;iostream&amp;gt;&lt;br&gt;&lt;br&gt;//Include the standard namespace library&lt;br&gt;using namespace std;&lt;br&gt;&lt;br&gt;//Beginning of the main function&lt;br&gt;int main ()&lt;br&gt;{&lt;br&gt;    //Prints Hello World! to the screen and&lt;br&gt;    //starts a new line using endl;&lt;br&gt;    cout &amp;lt;&amp;lt; "Hello World!" &amp;lt;&amp;lt; endl;&lt;br&gt;&lt;br&gt;    //Pauses the main loop, and resumes with user input&lt;br&gt;    system("Pause");&lt;br&gt;&lt;br&gt;    //return the value of zero&lt;br&gt;    return 0;&lt;br&gt;}&lt;br&gt;&lt;/blockquote&gt;&lt;div style="margin-left: 40px;"&gt;To compile and run this program copy and paste all of the above code into the visual c++ editor exactly as shown. Goto the debug menu and click "Start Debugging" or you can just press F5 on your keyboard. You should end up with something like this.&lt;br&gt;&lt;br&gt;&lt;div id="g2b5" style="padding: 1em 0pt; text-align: left;"&gt;&lt;img style="width: 500px; height: 400px;" src="http://docs.google.com/File?id=dc24prf_8fk7fw5f4"&gt;&lt;/div&gt;Now lets learn what each part of the code does.&lt;br&gt;&lt;b&gt;&lt;br&gt;&lt;/b&gt;&lt;u&gt;Descriptions from cplusplus!&lt;br&gt;&lt;br&gt;&lt;/u&gt;&lt;dl&gt;&lt;dt&gt;&lt;tt&gt;&lt;b&gt;//&lt;/b&gt;&lt;/tt&gt; This is a comment line. All lines beginning with two slash signs (&lt;tt&gt;//&lt;/tt&gt;) are considered comments and do not have any effect on the behavior of the program. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is. &lt;/dt&gt;&lt;/dl&gt;&lt;br&gt;&lt;b&gt;&lt;br&gt;#include &amp;lt;iostream&amp;gt;&lt;/b&gt;  Lines beginning with a pound sign (&lt;tt&gt;#&lt;/tt&gt;) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. In this case the directive &lt;tt&gt;#include &amp;lt;iostream&amp;gt;&lt;/tt&gt; tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program.&lt;br&gt;&lt;br&gt;&lt;dl&gt;&lt;dt&gt;&lt;tt&gt;&lt;b&gt;using namespace std;&lt;/b&gt;&lt;/tt&gt; All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name &lt;i&gt;std&lt;/i&gt;. So in order to access its functionality we declare with this expression that we will be using these entities. This line is very frequent in C++ programs that use the standard library, and in fact it will be included in most of the source codes included in these tutorials.&lt;br&gt;&lt;/dt&gt;&lt;dt&gt;&lt;br&gt;&lt;/dt&gt;&lt;dt&gt;&lt;br&gt;&lt;/dt&gt;&lt;dt&gt;&lt;tt&gt;&lt;b&gt;int main ()&lt;/b&gt;&lt;/tt&gt; This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it - the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. For that same reason, it is essential that all C++ programs have a &lt;tt&gt;main&lt;/tt&gt; function.&lt;/dt&gt;&lt;/dl&gt;The word &lt;tt&gt;main&lt;/tt&gt; is followed in the code by a pair of parentheses (&lt;tt&gt;()&lt;/tt&gt;). That is because it is a function declaration: In C++, what differentiates a function declaration from other types of expressions are these parentheses that follow its name. Optionally, these parentheses may enclose a list of parameters within them.&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Right after these parentheses we can find the body of the main function enclosed in braces (&lt;tt&gt;{}&lt;/tt&gt;). What is contained within these braces is what the function does when it is executed.&lt;br&gt; &lt;/p&gt;&lt;dl&gt;&lt;dt&gt;&lt;tt&gt;&lt;b&gt;cout &amp;lt;&amp;lt; "Hello World" &amp;lt;&amp;lt; endl;&lt;/b&gt;&lt;/tt&gt; This line is a C++ statement. A statement is a simple or compound expression that can actually produce some effect. In fact, this statement performs the only action that generates a visible effect in our first program.&lt;/dt&gt;&lt;/dl&gt;&lt;/div&gt;&lt;dl&gt;&lt;dd&gt;&lt;p&gt;&lt;tt&gt;cout&lt;/tt&gt; represents the standard output stream in C++, and the meaning of the entire statement is to insert a sequence of characters (in this case the &lt;tt&gt;Hello World&lt;/tt&gt; sequence of characters) into the standard output stream (which usually is the screen).&lt;/p&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;dl&gt;&lt;dd&gt;&lt;p&gt;&lt;tt&gt;cout&lt;/tt&gt; is declared in the &lt;tt&gt;iostream&lt;/tt&gt; standard file within the &lt;tt&gt;std&lt;/tt&gt; namespace, so that's why we needed to include that specific file and to declare that we were going to use this specific namespace earlier in our code.&lt;/p&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;div style="margin-left: 40px;"&gt;&lt;br&gt;&lt;p&gt;&amp;lt;&amp;lt; endl is used to end the line and start a new one, it is used mainly for formatting reasons.&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Notice that the statement ends with a semicolon character (&lt;tt&gt;;&lt;/tt&gt;). This character is used to mark the end of the statement and in fact it must be included at the end of all expression statements in all C++ programs (one of the most common syntax errors is indeed to forget to include some semicolon after a statement).&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;dl&gt;&lt;dt&gt;&lt;tt&gt;&lt;b&gt;return 0; &lt;/b&gt;&lt;/tt&gt;The return statement causes the main function to finish. return may be followed by a return code (in our example is followed by the return code &lt;tt&gt;0&lt;/tt&gt;). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ console program.&lt;/dt&gt;&lt;dt&gt;&lt;br&gt;&lt;/dt&gt;&lt;/dl&gt;&lt;/div&gt;&lt;b&gt;&lt;u&gt;Lesson Review:&lt;br&gt;&lt;/u&gt;&lt;/b&gt;&lt;div style="margin-left: 40px;"&gt;&lt;br&gt;Congratulations you are now a c++ programmer,  lets review what we just learned. &lt;br&gt;&lt;br&gt;&lt;div style="margin-left: 40px;"&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;How to make a new visual c++ project&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;How to add a source code to the project&lt;br&gt;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;How to make a basic hello world console application&lt;/b&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;In depth explanations of each part of the hello world program&lt;br&gt;&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;br style="font-weight: bold; text-decoration: underline;"&gt;&lt;br style="font-weight: bold; text-decoration: underline;"&gt;&lt;b&gt;&lt;u&gt;Practice Exercise:&lt;br&gt;&lt;/u&gt;&lt;/b&gt;&lt;div style="margin-left: 40px;"&gt;&lt;br&gt;C++ takes alot of practice so i will have a exercise at the end of each tutorial, i will try to make the exercises as interesting as possible.&lt;br&gt;&lt;br&gt;&lt;b&gt;Exercise:&lt;/b&gt; Mess around with the cout statement, try to make a program display a small paragraph. The most important thing is to get a feel for programming, stay tuned for my next tutorial, and if there any questions or suggestions then just leave me a comment.&lt;br&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;            &lt;/div&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2677128750081523261-6423317602151419718?l=ngsfuse.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://ngsfuse.blogspot.com/2008/01/intro-to-c-tutorials-created-by-fuse.html</link><author>noreply@blogger.com (Fuse)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></item></channel></rss>