title: How to make the program take in a list of integers?
body: <p>I just started learning c++ and is learning topics related to cin, cin.get. In one of my assignments, the requirement is this:</p>
  
  <p>Write a program that reads in a list of integer numbers and prints the largest and the
  smallest number.</p>
  
  <p>You can assume that the the user's input is always valid.</p>
  
  <p>You can assume that the numbers in the list are separated by one space character and
  that the character following the last number in the list is the newline character .</p>
  
  <p>Implement a loop in which the above actions are repeated until the user requests to quit.</p>
  
  <p>The code I came up with is:</p>
  
  <pre><code>using namespace std;
  int main()
  { 
  
      char ch = ' ';
      int max=0;
  
      do
      {
          int x;
          cin &gt;&gt; x;
          ch = cin.get();
          if (max = 0) { max = x; };
          if (x &gt; max) { max = x; };
      } while (ch != '\n');
      cout &lt;&lt; "maximum=" &lt;&lt; max &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>I was expecting to have this return the maximum of the numbers in the list. But it turned out only to return the last integer in the list.</p>
  
  <p>I also don't quite get why the line:</p>
  
  <pre><code>cin &gt;&gt; x;
  ch = cin.get();
  </code></pre>
  
  <p>makes the program able to accept a list of numbers. Isn't cin suppose to ask the user to input some stuff, as well as cin.get? In another word, shouldn't the user encounter input two times? But why is it when I run I am only asked to input once?</p>
  
  <p>After some adjustment using the comments in this post, I was able to come up with the code as such:</p>
  
  <pre><code>int main()
  </code></pre>
  
  <p>{ </p>
  
  <pre><code>cout &lt;&lt; "Enter the list of integer numbers: ";
  
  char ch = ' ';
  
  int max=0;
  int min = 0;
  
  do
  {
      int x;
  
      cin &gt;&gt; x;
  
      ch = cin.get();
  
      if (max == 0) { max = x; };
      if (x &gt; max) { max = x; };
  
      if (min == 0) { min = x; };
      if (x &lt; min) { min = x; };
  } while (ch != '\n');
  
  
  
  cout &lt;&lt; "maximum=" &lt;&lt; max &lt;&lt; endl;
  cout &lt;&lt; "minimum=" &lt;&lt; min &lt;&lt; endl;
  return 0;
  </code></pre>
  
  <p>My final question is: How can I satisfy the requirement of this assignment "Implement a loop in which the above actions are repeated until the user requests to quit."</p>