<?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.3 &#8212; Arrays and loops</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/</link>
	<description></description>
	<lastBuildDate>Thu, 09 Sep 2010 12:59:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: C++ Tutorial and Online Ebook</title>
		<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/comment-page-1/#comment-87428</link>
		<dc:creator>C++ Tutorial and Online Ebook</dc:creator>
		<pubDate>Wed, 30 Jun 2010 01:11:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/#comment-87428</guid>
		<description>[...] 6.3 Arrays and loops [...]</description>
		<content:encoded><![CDATA[<p>[...] 6.3 Arrays and loops [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesper</title>
		<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/comment-page-1/#comment-84916</link>
		<dc:creator>Jesper</dc:creator>
		<pubDate>Tue, 18 May 2010 21:54:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/#comment-84916</guid>
		<description>Hey  - the below code is copy pasted directly from Microsoft Visual 2010 and as far as i can see its exactly the same as the solution Alex posted. 

I&#039;m new to learning c++, and I&#039;m really enjoying following this tutorial. 

My question is this:
When i run the program it correctly keeps asking for a number between 1 and 9 as long as i input a number when prompted. However if I input a letter (Tried it to see what would happen incase of a misstype) it seems to go into an endless loop. Is it supposed to do that (with the code written) or is there another way to avoid this problem I should implement?

&lt;pre&gt;#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
using namespace std;

int main()
{
	int x;
	do
	{
		cout &lt;&lt; &quot;Please input a number between 1 and 9: &quot;;
		cin &gt;&gt; x;
	}	while (x &lt; 1 &#124;&#124; x &gt; 9);
	
	int anArray[9] = {4, 6, 7, 3, 8, 2, 1, 9, 5};
	for (int iii = 0; iii &lt; 9; iii++)
		cout &lt;&lt; anArray[iii] &lt;&lt; &quot; &quot;;
	
	cout &lt;&lt; endl;
	
	for (int jjj = 0; jjj &lt; 9; jjj++)
	{
		if (anArray[jjj] == x)
		{
			cout &lt;&lt; &quot;The number you entered (&quot; &lt;&lt; x &lt;&lt; &quot;) has index number: &quot; &lt;&lt; jjj &lt;&lt; endl;
			break;
		}
	}

	return 0;
}&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hey  &#8211; the below code is copy pasted directly from Microsoft Visual 2010 and as far as i can see its exactly the same as the solution Alex posted. </p>
<p>I&#8217;m new to learning c++, and I&#8217;m really enjoying following this tutorial. </p>
<p>My question is this:<br />
When i run the program it correctly keeps asking for a number between 1 and 9 as long as i input a number when prompted. However if I input a letter (Tried it to see what would happen incase of a misstype) it seems to go into an endless loop. Is it supposed to do that (with the code written) or is there another way to avoid this problem I should implement?</p>
<pre>#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
using namespace std;

int main()
{
	int x;
	do
	{
		cout &lt;&lt; &quot;Please input a number between 1 and 9: &quot;;
		cin &gt;&gt; x;
	}	while (x &lt; 1 || x &gt; 9);

	int anArray[9] = {4, 6, 7, 3, 8, 2, 1, 9, 5};
	for (int iii = 0; iii &lt; 9; iii++)
		cout &lt;&lt; anArray[iii] &lt;&lt; &quot; &quot;;

	cout &lt;&lt; endl;

	for (int jjj = 0; jjj &lt; 9; jjj++)
	{
		if (anArray[jjj] == x)
		{
			cout &lt;&lt; &quot;The number you entered (&quot; &lt;&lt; x &lt;&lt; &quot;) has index number: &quot; &lt;&lt; jjj &lt;&lt; endl;
			break;
		}
	}

	return 0;
}</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sagar</title>
		<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/comment-page-1/#comment-74973</link>
		<dc:creator>Sagar</dc:creator>
		<pubDate>Sun, 27 Dec 2009 23:45:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/#comment-74973</guid>
		<description>&lt;pre&gt; In solution number 2, shouldn&#039;t it be nNumber &gt; 1 &#124;&#124; nNumber &lt; 9 ?</description>
		<content:encoded><![CDATA[<pre> In solution number 2, shouldn't it be nNumber &gt; 1 || nNumber &lt; 9 ?</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mattias</title>
		<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/comment-page-1/#comment-72926</link>
		<dc:creator>Mattias</dc:creator>
		<pubDate>Tue, 24 Nov 2009 16:26:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/#comment-72926</guid>
		<description>For the second question, would this also work? (When each element in the array has a unique value of course)
If it has any downsides please let me know. 

&lt;pre&gt;
#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;


int main()
{
	using namespace std;
	int nInputNumber;
	do
	{
		cout &lt;&lt; &quot;Please enter a number between 1 and 9: &quot;;
		cin &gt;&gt; nInputNumber;
	}while((nInputNumber &lt; 0) &#124;&#124; (nInputNumber &gt;= 9));
	
	const int nArrayElements = 9;
	int anArray[nArrayElements] = { 4, 6, 7, 3, 8, 2, 1, 9, 5 };
	cout &lt;&lt;&quot;The array contains the following elements: &quot;;
	int nInputElement = -1;  // This will hold the place of the input number.
	for(int iii = 0; iii &lt; 9; iii++)
	{
		cout &lt;&lt; anArray[iii] &lt;&lt; &quot; &quot;;
		if(anArray[iii] == nInputNumber)
			nInputElement = iii+1;
	}
	cout &lt;&lt; endl;
	cout &lt;&lt; &quot;Your number was element number &quot; &lt;&lt; nInputElement &lt;&lt; &quot;.&quot; &lt;&lt; endl;
	return 0;
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>For the second question, would this also work? (When each element in the array has a unique value of course)<br />
If it has any downsides please let me know. </p>
<pre>
#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;

int main()
{
	using namespace std;
	int nInputNumber;
	do
	{
		cout &lt;&lt; &quot;Please enter a number between 1 and 9: &quot;;
		cin &gt;&gt; nInputNumber;
	}while((nInputNumber &lt; 0) || (nInputNumber &gt;= 9));

	const int nArrayElements = 9;
	int anArray[nArrayElements] = { 4, 6, 7, 3, 8, 2, 1, 9, 5 };
	cout &lt;&lt;&quot;The array contains the following elements: &quot;;
	int nInputElement = -1;  // This will hold the place of the input number.
	for(int iii = 0; iii &lt; 9; iii++)
	{
		cout &lt;&lt; anArray[iii] &lt;&lt; &quot; &quot;;
		if(anArray[iii] == nInputNumber)
			nInputElement = iii+1;
	}
	cout &lt;&lt; endl;
	cout &lt;&lt; &quot;Your number was element number &quot; &lt;&lt; nInputElement &lt;&lt; &quot;.&quot; &lt;&lt; endl;
	return 0;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: tnemmoC</title>
		<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/comment-page-1/#comment-67653</link>
		<dc:creator>tnemmoC</dc:creator>
		<pubDate>Wed, 02 Sep 2009 19:57:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/#comment-67653</guid>
		<description>I&#039;ve also noticed it happens when the input is above around 2 * 10^10 ... it kinda bothers me. Why doesn&#039;t it wrap around or something?</description>
		<content:encoded><![CDATA[<p>I&#8217;ve also noticed it happens when the input is above around 2 * 10^10 &#8230; it kinda bothers me. Why doesn&#8217;t it wrap around or something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: baldo</title>
		<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/comment-page-1/#comment-66187</link>
		<dc:creator>baldo</dc:creator>
		<pubDate>Thu, 13 Aug 2009 17:11:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/#comment-66187</guid>
		<description>The correct line must be:
&lt;pre&gt;} while ( h &lt;= 1 &#124;&#124; h &gt;= 9);&lt;!--formatted--&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>The correct line must be:</p>
<pre>} while ( h &lt;= 1 || h &gt;= 9);<!--formatted--></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: gundoganfa</title>
		<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/comment-page-1/#comment-63485</link>
		<dc:creator>gundoganfa</dc:creator>
		<pubDate>Wed, 01 Jul 2009 07:05:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/#comment-63485</guid>
		<description>it&#039;s better not to use &quot;goto statement&quot; unless really necessary.</description>
		<content:encoded><![CDATA[<p>it&#8217;s better not to use &#8220;goto statement&#8221; unless really necessary.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/comment-page-1/#comment-63162</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Fri, 26 Jun 2009 15:33:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/#comment-63162</guid>
		<description>&lt;pre&gt;#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;

int main()
{
int anArray[12] = { 4, 6, 7, 3, 8, 2, 1, 9, 5, 11, 14, 2 };

using namespace std;

cout &lt;&lt; &quot;Enter a number between 1 and 12: &quot;;

int h;
do
{
	cin &gt;&gt; h;
}	while (h = &lt;1 &#124;&#124; &gt;9);

cout &lt;&lt; anArray[h - 1];



while (1) ;	// Pause the program for debugging purposes

}

&lt;!--formatted--&gt;&lt;/pre&gt;

I&#039;m getting a &quot;syntax error : &#039;&lt;&#039;&quot; when I try to compile; it&#039;s pointing to this line: &lt;pre&gt;} while (h = &lt;1&lt;!--formatted--&gt;&lt;/pre&gt;

My code looks the same as yours!!!! This is driving me nuts! What have I done wrong?</description>
		<content:encoded><![CDATA[<pre>#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;

int main()
{
int anArray[12] = { 4, 6, 7, 3, 8, 2, 1, 9, 5, 11, 14, 2 };

using namespace std;

cout &lt;&lt; &quot;Enter a number between 1 and 12: &quot;;

int h;
do
{
	cin &gt;&gt; h;
}	while (h = &lt;1 || &gt;9);

cout &lt;&lt; anArray[h - 1];

while (1) ;	// Pause the program for debugging purposes

}

<!--formatted--></pre>
<p>I&#8217;m getting a &#8220;syntax error : &#8216;&lt;&#8217;&#8221; when I try to compile; it&#8217;s pointing to this line:
<pre>} while (h = &lt;1<!--formatted--></pre>
<p>My code looks the same as yours!!!! This is driving me nuts! What have I done wrong?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: FuturePixstar</title>
		<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/comment-page-1/#comment-62897</link>
		<dc:creator>FuturePixstar</dc:creator>
		<pubDate>Tue, 23 Jun 2009 02:06:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/#comment-62897</guid>
		<description>...typo

and this is just 4 students!

should be

and this is just 5 students... *sigh* I hate when people do that to me. 

Also I would like to thank you very very very much for all the work you put into this.
I&#039;m aspiring to be a programmer for pixar (or square-enix... not a fan of the new disney owners).
I&#039;m working on a game right now and when im done i just have to let all who plays it know about this site, its amazing. THX YOU!</description>
		<content:encoded><![CDATA[<p>&#8230;typo</p>
<p>and this is just 4 students!</p>
<p>should be</p>
<p>and this is just 5 students&#8230; *sigh* I hate when people do that to me. </p>
<p>Also I would like to thank you very very very much for all the work you put into this.<br />
I&#8217;m aspiring to be a programmer for pixar (or square-enix&#8230; not a fan of the new disney owners).<br />
I&#8217;m working on a game right now and when im done i just have to let all who plays it know about this site, its amazing. THX YOU!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: csvan</title>
		<link>http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/comment-page-1/#comment-60110</link>
		<dc:creator>csvan</dc:creator>
		<pubDate>Wed, 06 May 2009 08:12:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/63-arrays-and-loops/#comment-60110</guid>
		<description>Try removing the ++jjj inside the if statement. Does that help?</description>
		<content:encoded><![CDATA[<p>Try removing the ++jjj inside the if statement. Does that help?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
