C++ Homework, stuck with some edge cases and unusual input
<p>I have a C++ assignment to complete over the next couple of weeks.  The task is to </p>

<ol>
<li>read a line of input containing 3 scores between 0 and 89, and read a name from the same line.</li>
<li>Convert those scores to marks and give each student a grade depending on their marks.</li>
</ol>

<p>My first cut has done all of this (albeit in a messy way) and now I am thinking about invalid input.  The input I am really struggling with is how to deal with a user who keys in just the name:  i.e.      Smith, B.</p>

<p>Or what if one of the marks contains letters i.e. 10 c 20 Smith, B.</p>

<p>At the moment my program just reads it as an int I think and tries to carry on anyway - I want it to treat this as a string and output:  "Bad input line: Smith, B."</p>

<p>Is there a way that experienced programmers deal with things like this?  I don't want to create a mess of if statements everywhere in my code as that makes it hard to follow.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

//function to check input validity
bool validateInput(int mark1, int mark2, int mark3, string name);
//function to check the scores
int checkScores(int mark1, int mark2, int mark3);

int main()
{
    int mark1 = 0, mark2 = 0, mark3 = 0;
    string name;

    cin &gt;&gt; mark1 &gt;&gt; mark2 &gt;&gt; mark3;
    getline (cin, name);
    // continue if the input is valid
    if (validateInput(mark1, mark2, mark3, name) == true)
    {
        checkScores(mark1, mark2, mark3);
    }
    else cout &lt;&lt; "Bad Input Line: \t" &lt;&lt;
    mark1 &lt;&lt; " " &lt;&lt; mark2 &lt;&lt; " " &lt;&lt; mark3
    &lt;&lt; " " &lt;&lt; name &lt;&lt; endl;

    return 0;
}

bool validateInput(int mark1, int mark2, int mark3, string name)
{
    //return false if the scores are not valid
    if (mark1 &lt; 0 || mark1 &gt; 50 || mark2 &lt; 0 || mark2 &gt; 50 || mark3 &lt; 0 || mark3 &gt; 50)
    {
        return false;
    }
    return true;
}

int checkScores(int mark1, int mark2, int mark3)
{
    int mark1Mark = 0, mark2Mark = 0, mark3Mark = 0;
    string candidateType;
    //return the mark for the mark1 test
    if (mark1 &lt;= 10) mark1Mark = 1;
    else if (mark1 &lt;= 20) mark1Mark = 2;
    else if (mark1 &lt;= 30) mark1Mark = 3;
    else if (mark1 &lt;= 40) mark1Mark = 4;
    else if (mark1 &lt;= 50) mark1Mark = 5;
    //return the mark for the mark2 test
    if (mark2 &lt;= 10) mark2Mark = 1;
    else if (mark2 &lt;= 20) mark2Mark = 2;
    else if (mark2 &lt;= 30) mark2Mark = 3;
    else if (mark2 &lt;= 40) mark2Mark = 4;
    else if (mark2 &lt;= 50) mark2Mark = 5;
    //return the mark for the mark3 test
    if (mark3 &lt;= 10) mark3Mark = 1;
    else if (mark3 &lt;= 20) mark3Mark = 2;
    else if (mark3 &lt;= 30) mark3Mark = 3;
    else if (mark3 &lt;= 40) mark3Mark = 4;
    else if (mark3 &lt;= 50) mark3Mark = 5;

    if (mark1Mark &gt;= 5 &amp;&amp; mark2Mark &gt;= 5 &amp;&amp; mark3Mark &gt;= 5)
        candidateType = "Exceptional";
    else if (mark3Mark &gt;= 2 &amp;&amp; mark2Mark &gt;= 2  &amp;&amp; mark1Mark &gt;= 2)
        candidateType = "Pass";
    else candidateType = "Fail";

    cout &lt;&lt; mark1Mark &lt;&lt; " " &lt;&lt; mark2Mark &lt;&lt; " " &lt;&lt; mark3Mark &lt;&lt; " " &lt;&lt; candidateType;
}
</code></pre>
