Input reading: two values (separated by whitespace) per line
I can think of two more ways of doing it.

1. Using iostream iterators. (Following code is from here)

#include &lt;iostream&gt;
#include &lt;iterator&gt;
using namespace std;

int main () {
  double value1, value2;
  cout &lt;&lt; "Please, insert two values: ";

  istream_iterator&lt;double&gt; eos;         // end-of-stream iterator
  istream_iterator&lt;double&gt; iit (cin);   // stdin iterator

  if (iit!=eos) value1=*iit;

  iit++;
  if (iit!=eos) value2=*iit;

  cout &lt;&lt; value1 &lt;&lt; "*" &lt;&lt; value2 &lt;&lt; "=" &lt;&lt; (value1*value2) &lt;&lt; endl;

  return 0;
}


2. Converting string to int using atoi() rest everything will be same.