<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Beginner]]></title><description><![CDATA[<p>Hi there, i'm a beginner when it comes to C++... I use Bloodshed C++ to make beginners console applications, these tasks and classes are for school by the way... Yesterday i made a somewhat different Hello World app. This is the source-code:</p>
<pre><code># include &lt;iostream&gt;
using namespace std;

int main()
{
string name1;
int age1;

cout &lt;&lt; &quot;What is your name&quot; &lt;&lt; endl;
getline (cin, name1 );

cout &lt;&lt; &quot;What is your age?&quot; &lt;&lt; endl;
cin &gt;&gt;age1;
cin.get();

if (age1 &gt;= 18)
{
cout &lt;&lt; &quot; Hi there &quot; &lt;&lt; name1 &lt;&lt; &quot;, you are allowed to enter&quot;;
}

else 
{
    cout &lt;&lt; &quot;Hi there &quot; &lt;&lt;name1 &lt;&lt; &quot;, Rascar Capac sens you his regards&quot;;
}
cout &lt;&lt; &quot;&quot; &lt;&lt; endl;
cout &lt;&lt; &quot; Made by Rascar C.&quot; &lt;&lt; endl;

cin.get();
return 0;
}
</code></pre>
<p>Now i have a question wich i hope you will help me with... When i enter a letter when there is asked for my age, the program quits on its own. How do i make sure that when someone enters a letter instead of a number, there will be a message the input is not correct, so the program will take them back to the name/ age option. I really hope you can help me with this..</p>
<p>Greetings, Rascar... :)[code]</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/142300/beginner</link><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Sep 2026 16:47:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/142300.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 29 Mar 2006 11:54:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Beginner on Wed, 29 Mar 2006 11:54:34 GMT]]></title><description><![CDATA[<p>Hi there, i'm a beginner when it comes to C++... I use Bloodshed C++ to make beginners console applications, these tasks and classes are for school by the way... Yesterday i made a somewhat different Hello World app. This is the source-code:</p>
<pre><code># include &lt;iostream&gt;
using namespace std;

int main()
{
string name1;
int age1;

cout &lt;&lt; &quot;What is your name&quot; &lt;&lt; endl;
getline (cin, name1 );

cout &lt;&lt; &quot;What is your age?&quot; &lt;&lt; endl;
cin &gt;&gt;age1;
cin.get();

if (age1 &gt;= 18)
{
cout &lt;&lt; &quot; Hi there &quot; &lt;&lt; name1 &lt;&lt; &quot;, you are allowed to enter&quot;;
}

else 
{
    cout &lt;&lt; &quot;Hi there &quot; &lt;&lt;name1 &lt;&lt; &quot;, Rascar Capac sens you his regards&quot;;
}
cout &lt;&lt; &quot;&quot; &lt;&lt; endl;
cout &lt;&lt; &quot; Made by Rascar C.&quot; &lt;&lt; endl;

cin.get();
return 0;
}
</code></pre>
<p>Now i have a question wich i hope you will help me with... When i enter a letter when there is asked for my age, the program quits on its own. How do i make sure that when someone enters a letter instead of a number, there will be a message the input is not correct, so the program will take them back to the name/ age option. I really hope you can help me with this..</p>
<p>Greetings, Rascar... :)[code]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1026389</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1026389</guid><dc:creator><![CDATA[Rascar-Capac]]></dc:creator><pubDate>Wed, 29 Mar 2006 11:54:34 GMT</pubDate></item><item><title><![CDATA[Reply to Beginner on Wed, 29 Mar 2006 12:30:42 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>wrong board, post to ANSI C or C++ next time. Moreover you could use the cpp tags to enable syntax highlighting.</p>
<p>To solve your problem, I used a char instead of an int and a do-while loop to check whether the entered age is a digit:</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;

using namespace std;

int main() {
  string name1;
  char age1;

  do {
    cout &lt;&lt; &quot;What is your name\n&quot;;
    getline (cin, name1 );

    cout &lt;&lt; &quot;What is your age?\n&quot;;
    cin &gt;&gt; age1;
    cin.get();

    if (age1 &gt;= 18)
      cout &lt;&lt; &quot; Hi there &quot; &lt;&lt; name1 &lt;&lt; &quot;, you are allowed to enter.&quot;;
    else 
      cout &lt;&lt; &quot;Hi there &quot; &lt;&lt; name1 &lt;&lt; &quot;, Rascar Capac sends you his regards.&quot;;
  }
  while (!isdigit(age1));

  cout &lt;&lt; &quot;\nMade by Rascar C.\n&quot;;

  cin.get();
  return 0;
}
</code></pre>
<p>Bye</p>
<p>GPC</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1026436</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1026436</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Wed, 29 Mar 2006 12:30:42 GMT</pubDate></item><item><title><![CDATA[Reply to Beginner on Wed, 29 Mar 2006 13:02:18 GMT]]></title><description><![CDATA[<p>Thank you very much <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1026467</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1026467</guid><dc:creator><![CDATA[Rascar-Capac]]></dc:creator><pubDate>Wed, 29 Mar 2006 13:02:18 GMT</pubDate></item></channel></rss>