<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 6.2 &#8212; Arrays (Part II)</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 21:20:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: anwar002</title>
		<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/comment-page-1/#comment-95650</link>
		<dc:creator>anwar002</dc:creator>
		<pubDate>Fri, 01 Jul 2011 15:05:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/#comment-95650</guid>
		<description>I wrote the follwoing program: ( based on quiz 2 above)

{
	//
	enum Animals {chicken, dog, cat, elephant, duck, snake, maxAnimal};
	int numberofLegs []={2,4,4,4,2,0};
	for (int iii = 0; iii &lt;=snake ; iii ++)
		cout &lt;&lt; iii  &lt;&lt; &quot; &quot; &lt;&lt; numberofLegs[iii]&lt;&lt; endl;
	cout &lt;&lt; &quot;Chicken has  &quot; &lt;&lt; numberofLegs[chicken] &lt;&lt; &quot; legs \n&quot; ;

}

How can I make it print

chicken has 2 legs
dog     has 4 legs
cat     has 4 legs
etc.
using the iii values?
How do we access a member of an enum type?
Thanks</description>
		<content:encoded><![CDATA[<p>I wrote the follwoing program: ( based on quiz 2 above)</p>
<p>{<br />
	//<br />
	enum Animals {chicken, dog, cat, elephant, duck, snake, maxAnimal};<br />
	int numberofLegs []={2,4,4,4,2,0};<br />
	for (int iii = 0; iii &lt;=snake ; iii ++)<br />
		cout &lt;&lt; iii  &lt;&lt; &quot; &quot; &lt;&lt; numberofLegs[iii]&lt;&lt; endl;<br />
	cout &lt;&lt; &quot;Chicken has  &quot; &lt;&lt; numberofLegs[chicken] &lt;&lt; &quot; legs \n&quot; ;</p>
<p>}</p>
<p>How can I make it print</p>
<p>chicken has 2 legs<br />
dog     has 4 legs<br />
cat     has 4 legs<br />
etc.<br />
using the iii values?<br />
How do we access a member of an enum type?<br />
Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rajen</title>
		<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/comment-page-1/#comment-95420</link>
		<dc:creator>rajen</dc:creator>
		<pubDate>Fri, 06 May 2011 23:42:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/#comment-95420</guid>
		<description>hello alex i have to write a program that calculate the average body mass of 5 people on the basis of their hight and weight using 2 dimensional array. where i need to use for loop, while loop, switch statement for display the menu and pointers i am totally confused with this can you plz help me for this?

BMI= weight(kg)/height2(m)</description>
		<content:encoded><![CDATA[<p>hello alex i have to write a program that calculate the average body mass of 5 people on the basis of their hight and weight using 2 dimensional array. where i need to use for loop, while loop, switch statement for display the menu and pointers i am totally confused with this can you plz help me for this?</p>
<p>BMI= weight(kg)/height2(m)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: prafull.badyal</title>
		<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/comment-page-1/#comment-95086</link>
		<dc:creator>prafull.badyal</dc:creator>
		<pubDate>Sat, 01 Jan 2011 04:11:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/#comment-95086</guid>
		<description>we can&#039;t use arrays with if?? like 


if(array[2]=xyz)
{
do this;
}
else
thiz;</description>
		<content:encoded><![CDATA[<p>we can&#8217;t use arrays with if?? like </p>
<p>if(array[2]=xyz)<br />
{<br />
do this;<br />
}<br />
else<br />
thiz;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MrAlshahawy</title>
		<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/comment-page-1/#comment-90884</link>
		<dc:creator>MrAlshahawy</dc:creator>
		<pubDate>Thu, 26 Aug 2010 00:56:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/#comment-90884</guid>
		<description>No , Don&#039;t get confused between array declaration and accessing array element , if you want to have an array with 5 elements you write :

&lt;pre&gt;
int adHighTemperature[5];
&lt;/pre&gt;

when you need to access one of the array elements you have to follow the &quot;Zero based index rule&quot;.

&lt;pre&gt;
adHighTemperature[0] = 5;// The first element.

adHighTemperature[4] = 6;// The last element.
&lt;/pre&gt;

I hope you got it now.</description>
		<content:encoded><![CDATA[<p>No , Don&#8217;t get confused between array declaration and accessing array element , if you want to have an array with 5 elements you write :</p>
<pre>
int adHighTemperature[5];
</pre>
<p>when you need to access one of the array elements you have to follow the &#8220;Zero based index rule&#8221;.</p>
<pre>
adHighTemperature[0] = 5;// The first element.

adHighTemperature[4] = 6;// The last element.
</pre>
<p>I hope you got it now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C++ Tutorial and Online Ebook</title>
		<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/comment-page-1/#comment-87406</link>
		<dc:creator>C++ Tutorial and Online Ebook</dc:creator>
		<pubDate>Wed, 30 Jun 2010 00:58:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/#comment-87406</guid>
		<description>[...] 6.2 Arrays (Part II) [...]</description>
		<content:encoded><![CDATA[<p>[...] 6.2 Arrays (Part II) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/comment-page-1/#comment-79565</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Wed, 03 Mar 2010 04:40:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/#comment-79565</guid>
		<description>&lt;b&gt;&lt;i&gt;Ahh!! of course. So isn’t there anyway we can declare an array of indefinite size and according to the input, let it calculate itself what the size should be ?&lt;/i&gt;&lt;/b&gt;

Yes, there is a way to do that, but that is a more advanced topic that is covered later, in section 6.9 (Dynamic Memory Allocation).</description>
		<content:encoded><![CDATA[<p><b><i>Ahh!! of course. So isn’t there anyway we can declare an array of indefinite size and according to the input, let it calculate itself what the size should be ?</i></b></p>
<p>Yes, there is a way to do that, but that is a more advanced topic that is covered later, in section 6.9 (Dynamic Memory Allocation).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: replax</title>
		<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/comment-page-1/#comment-78507</link>
		<dc:creator>replax</dc:creator>
		<pubDate>Wed, 17 Feb 2010 20:07:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/#comment-78507</guid>
		<description>This is the print app for exercise 2:
&lt;pre&gt;
#include &lt;iostream&gt;

using namespace std;

int main()
{
	enum eAnimal
	{
		CHICKEN,
		DOG,
		CAT,
		ELEPHANT,
		DUCK,
		SNAKE,
		TOTAL_ANIMALS
	};

	int anAnimalLegs[TOTAL_ANIMALS] = { 4, 4, 4, 4, 2, 0 };

	for(int iii = 0; iii &lt; TOTAL_ANIMALS; iii++)
	{
		cout &lt;&lt; &quot;Animal Legs: &quot; &lt;&lt; anAnimalLegs[iii] &lt;&lt; endl;
	}

	char exit;
	cin &gt;&gt; exit;
	return 0;
}
&lt;/pre&gt;

thanks for the free tutorials btw, theyre great!!</description>
		<content:encoded><![CDATA[<p>This is the print app for exercise 2:</p>
<pre>
#include &lt;iostream&gt;

using namespace std;

int main()
{
	enum eAnimal
	{
		CHICKEN,
		DOG,
		CAT,
		ELEPHANT,
		DUCK,
		SNAKE,
		TOTAL_ANIMALS
	};

	int anAnimalLegs[TOTAL_ANIMALS] = { 4, 4, 4, 4, 2, 0 };

	for(int iii = 0; iii &lt; TOTAL_ANIMALS; iii++)
	{
		cout &lt;&lt; &quot;Animal Legs: &quot; &lt;&lt; anAnimalLegs[iii] &lt;&lt; endl;
	}

	char exit;
	cin &gt;&gt; exit;
	return 0;
}
</pre>
<p>thanks for the free tutorials btw, theyre great!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mayur</title>
		<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/comment-page-1/#comment-76150</link>
		<dc:creator>Mayur</dc:creator>
		<pubDate>Sun, 10 Jan 2010 19:26:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/#comment-76150</guid>
		<description>Ahh!! of course. So isn&#039;t there anyway we can declare an array of indefinite size and according to the input, let it calculate itself what the size should be ?</description>
		<content:encoded><![CDATA[<p>Ahh!! of course. So isn&#8217;t there anyway we can declare an array of indefinite size and according to the input, let it calculate itself what the size should be ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: caboosethepantless</title>
		<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/comment-page-1/#comment-75634</link>
		<dc:creator>caboosethepantless</dc:creator>
		<pubDate>Mon, 04 Jan 2010 02:57:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/#comment-75634</guid>
		<description>The compiler needs to know how big the array is at compile time, which means...

&lt;pre&gt;    int sampArray[] = { 0 }; &lt;/pre&gt;

... is telling the compiler that when the program is run, to allocate space for one element, and store 0 in element 0.

Since your array only has one element, trying to store values in the non-existent element 1, element 2, or so on will cause the program to be unstable.</description>
		<content:encoded><![CDATA[<p>The compiler needs to know how big the array is at compile time, which means&#8230;</p>
<pre>    int sampArray[] = { 0 }; </pre>
<p>&#8230; is telling the compiler that when the program is run, to allocate space for one element, and store 0 in element 0.</p>
<p>Since your array only has one element, trying to store values in the non-existent element 1, element 2, or so on will cause the program to be unstable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mayur Gupta</title>
		<link>http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/comment-page-1/#comment-74392</link>
		<dc:creator>Mayur Gupta</dc:creator>
		<pubDate>Thu, 17 Dec 2009 18:01:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/62-arrays-part-ii/#comment-74392</guid>
		<description>Hello Alex, 

Can you help me in understanding the following program? 
The motive of the program is to ask the user as many numbers as he wishes, and then if he want to stop he can enter zero(0) value. Once that is done, the program will show how many elements he had entered to the array.
But the following program prints out incorrect values and crashes. I can&#039;t figure out what is going wrong and where.

The Code: 
&lt;pre&gt;#include &lt;iostream&gt;
using namespace std;

int main()
{
    int sampArray[] = { 0 };
    int x = -1;
    int count = 0;
    while (x != 0)
    {
        cout &lt;&lt; &quot;Enter a number: &quot;;
        cin &gt;&gt; x;
        if (x != 0)
        {
            sampArray[count] = x;
            count++;
        }
    }
    cout &lt;&lt; &quot;Size of the array: \t\t &quot; &lt;&lt; sizeof(sampArray) &lt;&lt; endl;
    cout &lt;&lt; &quot;Total elements in the array: \t\t &quot; &lt;&lt; sizeof(sampArray) / sizeof(sampArray[0]) &lt;&lt; endl;

    return 0;
}&lt;/pre&gt;


The Output: 
&lt;pre&gt;Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
Enter a number: 6
Enter a number: 7
Enter a number: 8
Enter a number: 9
Enter a number: 0
Size of the array: 4
Total elements in the array: 1&lt;/pre&gt;

Regards,
Mayur</description>
		<content:encoded><![CDATA[<p>Hello Alex, </p>
<p>Can you help me in understanding the following program?<br />
The motive of the program is to ask the user as many numbers as he wishes, and then if he want to stop he can enter zero(0) value. Once that is done, the program will show how many elements he had entered to the array.<br />
But the following program prints out incorrect values and crashes. I can&#8217;t figure out what is going wrong and where.</p>
<p>The Code: </p>
<pre>#include &lt;iostream&gt;
using namespace std;

int main()
{
    int sampArray[] = { 0 };
    int x = -1;
    int count = 0;
    while (x != 0)
    {
        cout &lt;&lt; &quot;Enter a number: &quot;;
        cin &gt;&gt; x;
        if (x != 0)
        {
            sampArray[count] = x;
            count++;
        }
    }
    cout &lt;&lt; &quot;Size of the array: \t\t &quot; &lt;&lt; sizeof(sampArray) &lt;&lt; endl;
    cout &lt;&lt; &quot;Total elements in the array: \t\t &quot; &lt;&lt; sizeof(sampArray) / sizeof(sampArray[0]) &lt;&lt; endl;

    return 0;
}</pre>
<p>The Output: </p>
<pre>Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
Enter a number: 6
Enter a number: 7
Enter a number: 8
Enter a number: 9
Enter a number: 0
Size of the array: 4
Total elements in the array: 1</pre>
<p>Regards,<br />
Mayur</p>
]]></content:encoded>
	</item>
</channel>
</rss>

