if statement for input (cin)
<p>Practicing some C++, I ran into some code from a book.
The usage of the if statement with the break seams a bit unecessary to me:   </p>

<p>if (!(cin >> dstep)) 
break; </p>

<p>This seams a bit hackish to me and simply using a cin >> dstep with no if or break runs the program fine.  Any thoughts?</p>

<pre><code>                    int main()
                {
                    using namespace VECTOR;

                    srand(time(0));     //seed random-number generator
                    double direction;
                    Vector step;        //creates default object
                    Vector result(0.0, 0.0);    //
                    unsigned long steps = 0;
                    double target;
                    double dstep;

                    cout &lt;&lt; "Enter target distance (q to quit): ";

                    while (cin &gt;&gt; target)
                    {
                        cout &lt;&lt; "Enter step length: ";
                        if (!(cin &gt;&gt; dstep))    //if NOT inputing into dstep THEN break/means if INPUTING is TRUE, keep going and don't break out of loop
                            break; 
                      //cin &gt;&gt; dstep  // why not just use this?
                        while (result.magval() &lt; target)
                        {
                            direction = rand() % 360;
                            step.set(dstep, direction, 'p'); //sets the values dstep and direction based on the form; in this case 'p'
                            result = result + step;
                            steps++;
                        }
                        cout &lt;&lt; "After " &lt;&lt; steps &lt;&lt; " steps, the subject "
                            "has the following location:\n";
                        cout &lt;&lt; result &lt;&lt; endl;
                        result.polar_mode();
                        cout &lt;&lt; " or\n" &lt;&lt; result &lt;&lt; endl;
                        cout &lt;&lt; "Average outward distance per step = "
                            &lt;&lt; result.magval() / steps &lt;&lt; endl;
                        steps = 0;
                        result.set(0.0, 0.0);
                        cout &lt;&lt; "Enter target distance (q to quit): ";
                    }
                    cout &lt;&lt; "Bye!\n";

                    cin.get();
                    return 0;
                }
</code></pre>
