title: Validate string input in c++ for letters and spaces only
body: <p>I haven't got to know a lot about functions yet since I'm just at chapter 4 (which is decision making using if, else) of Starting Out with C++ book. 
  Here my problem asks me to enter the inputs of runner names and their timer so I could rank them in 1st 2nd and 3rd place. </p>
  
  <p>I'm having trouble to validate the input for the string for runners's names as letters and spaces only. 
  I'm thinking about using loop or bool but I don't know what is the proper way to put it. </p>
  
  <p>Can somebody show me what function I can use best in this case without repeating step into multiple lines of codes.
  I'm sorry in advance for my long version code, I'm also looking for the way to shorten it.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt; // for setw, setpresicion, control output
  #include &lt;cctype&gt; // for getline, cin.
  
  using namespace std;
  
  int main()
  {
      string runner1, runner2, runner3;
      double time1, time2, time3;
  
  
      cout &lt;&lt; "Enter Runner 1 name: ";
      getline(cin, runner1);
      cout &lt;&lt; "Enter Runner 2 name: ";
      getline(cin, runner2);
      cout &lt;&lt; "Enter Runner 3 name: ";
      getline(cin, runner3);
  
      cout &lt;&lt; runner1 &lt;&lt; "'s finishing time: ";
      cin &gt;&gt; time1;
      while (!cin || (time1 &lt; 0)){              //the # is negative
          cout &lt;&lt; "Please enter a non-negative number!\n";
          cin &gt;&gt; time1;
      }
      cout &lt;&lt; runner2 &lt;&lt; "'s finishing time: ";
      cin &gt;&gt; time2;
      while (!cin || (time2 &lt; 0)){              //the # is negative
          cout &lt;&lt; "Please enter a non-negative number!\n";
          cin &gt;&gt; time2;
      }
      cout &lt;&lt; runner3 &lt;&lt; "'s finishing time: ";
      cin &gt;&gt; time3;
      while (!cin || (time3 &lt; 0)){
          cout &lt;&lt; "Please enter a non-negative number!\n";
          cin &gt;&gt; time3;
      }
  
      // This is for Rank1----------------------------
          cout &lt;&lt; "1st place : ";
          if((time1 &lt; time2)&amp;&amp;(time1 &lt; time3))
          {
              cout &lt;&lt; left &lt;&lt; setw(5) &lt;&lt; runner1 &lt;&lt; " " &lt;&lt; right
              &lt;&lt; setw(5) &lt;&lt; time1 &lt;&lt; endl;
          }
          else if (time2 &lt; time3){
              cout &lt;&lt; left &lt;&lt; setw(5) &lt;&lt; runner2 &lt;&lt; " " &lt;&lt; right
              &lt;&lt; setw(5)  &lt;&lt; time2 &lt;&lt; endl;
          }
          else {
              cout &lt;&lt; left &lt;&lt; setw(5) &lt;&lt; runner3 &lt;&lt; " " &lt;&lt; right
              &lt;&lt; setw(5) &lt;&lt; time3 &lt;&lt; endl;
          }
          //Rank2------------------------------------
          cout &lt;&lt; "2nd place : ";
          if ((time1 &lt; time2)&amp;&amp;(time3 &lt; time1)){
              cout &lt;&lt; left &lt;&lt; setw(5) &lt;&lt; runner1 &lt;&lt; " " &lt;&lt; right
              &lt;&lt; setw(5) &lt;&lt; time1 &lt;&lt; endl;
          }
          else if ((time3 &lt; time2)&amp;&amp;(time1 &lt; time3)){
              cout &lt;&lt; left &lt;&lt; setw(5) &lt;&lt; runner3 &lt;&lt; " " &lt;&lt; right
              &lt;&lt; setw(5) &lt;&lt; time3 &lt;&lt; endl;
          }
          else {
              cout &lt;&lt; left &lt;&lt; setw(5) &lt;&lt; runner2 &lt;&lt; " " &lt;&lt; right
              &lt;&lt;setw(5) &lt;&lt; time2 &lt;&lt; endl;
          }
          // RANK 3-----------------------------------
          cout &lt;&lt; "3rd place : ";
          if ((time1 &gt; time2)&amp;&amp;(time1 &gt; time3)){
              cout &lt;&lt; left &lt;&lt; setw(5) &lt;&lt; runner1 &lt;&lt; " " &lt;&lt; right
              &lt;&lt; setw(5) &lt;&lt; time1 &lt;&lt; endl;
          }
          else if ((time1 &lt; time3)&amp;&amp;(time3 &gt; time2)){
              cout &lt;&lt; left &lt;&lt; setw(5) &lt;&lt; runner3 &lt;&lt; " " &lt;&lt; right
              &lt;&lt; setw(5) &lt;&lt; time3 &lt;&lt; endl;
          }
          else {
              cout &lt;&lt; left &lt;&lt; setw(5) &lt;&lt; runner2 &lt;&lt; " " &lt;&lt; right
              &lt;&lt;setw(5) &lt;&lt; time2 &lt;&lt; endl;
          }
  
  
  
      return 0;
  }
  </code></pre>