title: Min, Max, Range
body: <p>I have a problem approaching this problem. It says that I have let the program find the min, max, and range when the User enter a min range and a max range.</p>
  
  <p>Here it the code I have:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;cmath&gt;
  #include &lt;iomanip&gt;
  #define pi 3.1416
  #define POINTS 20
  
  
  using namespace std;
  
  int main()
  {
  
      int Xmin, Xmax;
      double step;
  
      cout &lt;&lt; "Enter a value for xMin and xMax:\n";
      cin &gt;&gt; Xmin &gt;&gt; Xmax;
  
  
      step = (double)(Xmax - Xmin) / (double)POINTS;
  
      cout &lt;&lt; "X-VALUES " &lt;&lt; "" &lt;&lt; "| " &lt;&lt; "" &lt;&lt; "Y-VALUES" &lt;&lt; endl;
      cout &lt;&lt; "_________" &lt;&lt; "" &lt;&lt; "|_" &lt;&lt; "" &lt;&lt; "_________" &lt;&lt; endl;
  
  
  
      for (int i = 0; i &lt; POINTS; ++i)
      {
  
          double x = Xmin + (step * i);
  
          double y = 0.0572 * cos(4.667 * x) + 0.0218 * pi * cos(12.22 * x);
  
  
          cout &lt;&lt; x &lt;&lt; "\t     " &lt;&lt; setprecision(2) &lt;&lt; y &lt;&lt; endl;
      }
  
      cout &lt;&lt; "____________________" &lt;&lt; endl;
  
  
      return 0;
  }
  </code></pre>
  
  <p>I here is the output of my program:</p>
  
  <pre><code>X-Value   |   Y-Value
  __________|__________
   -2           -0.0043
   -1.8         -0.0982
   -1.6         0.0378
   -1.4         0.0438
   -1.2         0.0099
   -1           0.0618
   -0.8         -0.1118
   -0.6         -0.0198
   -0.4         -0.0047
   -0.2         -0.0184
   0            0.1257
   0.2          -0.0184
   0.4          -0.0047
   0.6          -0.0198
   0.8          -0.1118
   1            0.0618
   1.2          0.0099
   1.4          0.0438
   1.6          0.0738
   1.8          -0.0982
   2            -0.0043
  ─────────────────────
  </code></pre>
  
  <p>Basically, this program all ready has a equation that calculates the numbers and list them based on the users inputs for  Xmin and Xmax. I'm suppose to let the program find the min, max, and calculate it's range from the Y-Values from the table above.</p>
  
  <p>Here is my code for finding min and max.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;cmath&gt;
  #include &lt;iomanip&gt;
  #include &lt;limits&gt;
  #define pi 3.1416
  #define POINTS 20
  
  
  using namespace std;
  
  int main()
  {
  
      int Xmin, Xmax;
      double step;
      int max = numeric_limits&lt;int&gt; :: min();
      int min = numeric_limits&lt;int&gt; :: max();
      int num = 0;
  
      cout &lt;&lt; "Enter a value for xMin and xMax:\n";
      cin &gt;&gt; Xmin &gt;&gt; Xmax;
  
  
      step = (double)(Xmax - Xmin) / (double)POINTS;
  
      cout &lt;&lt; "X-VALUES " &lt;&lt; "" &lt;&lt; "| " &lt;&lt; "" &lt;&lt; "Y-VALUES" &lt;&lt; endl;
      cout &lt;&lt; "_________" &lt;&lt; "" &lt;&lt; "|_" &lt;&lt; "" &lt;&lt; "_________" &lt;&lt; endl;
  
  
  
      for (int i = 0; i &lt; POINTS; ++i)
      {
  
          double x = Xmin + (step * i);
  
          double y = 0.0572 * cos(4.667 * x) + 0.0218 * pi * cos(12.22 * x);
  
          //printf(" %f\t%f\n ", x, y);
          cout &lt;&lt; x &lt;&lt; "\t     " &lt;&lt; setprecision(2) &lt;&lt; y &lt;&lt; endl;
      }
  
      cout &lt;&lt; "____________________" &lt;&lt; endl;
  
      while (cout &lt;&lt; "Enter a value for xMin and xMax:\n" &amp;&amp;
          cin &gt;&gt; Xmin &gt;&gt; Xmax)
      {
          if (num &gt; max) max = num;
          if (num &lt; min) min = num;
      }
  
      cout &lt;&lt; "max is: " &lt;&lt; max &lt;&lt; '\n'
          &lt;&lt; "min is: " &lt;&lt; min &lt;&lt; '\n';
  
  
      return 0;
  }
  </code></pre>
  
  <p>It runs, but it doesn't print out the min or max. It just repeats the program at "enter Xmin and Xmax". But when I enter a any leter it prints out the min and max. Help me. I'm confused.</p>