so i tried sorting arr2 from lowest to highest value, but it only gives me 4 values and then the rest are zero. Any thoughts on how to fix this?

#include <iostream> 
#include <iomanip>
using namespace std;

int main()
{

   cout << fixed << setprecision(1);
   float userMin;
   float userMax;

   const int SIZE = 21;
   float arr[SIZE];
   const int SIZE2 = 21;
   float arr2[SIZE2];
   int count = 0;
   cout << "enter min ";
   cin >> userMin;
   cout << "enter max ";
   cin >> userMax;
   float inc = (userMax - userMin) / (SIZE-1);
   float x = inc*count + userMin;




   for (; x <= userMax;)
   {
      for (int e = 0; e < SIZE; e++)
      {
         arr[e] = x;
         arr2[e] = (0.0572*cos(4.667*x) + 0.0218*cos(12.22*x));
         cout << setw(15) << setprecision(1)<< arr[e]
            << setw(15) << setprecision(3) << arr2[e]
            << endl;


         count++;
         x = userMin + inc*count;


      }
   }


   int temp;


      for (int e = 0; e < SIZE-1; e++)
      {

         for (int j = e+1; j < SIZE; j++)
         {

            if (arr2[e] > arr2[j])
            {
               temp = arr2[e];
               arr2[e] = arr2[j];
               arr2[j] = temp;

            }

         }
      }

      for (int e = 0; e < SIZE; e++)
      {
         cout << "sorted: " << arr2[e] << endl;
      }

   return 0;
}

What is the value of count when you exit for (; x <= userMax;)?

Why don't you just use qsort() to do this? It is a standard C function that works fine with scalar arrays like this in C++. I use it all the time, if needed. It is fast, proven, efficient (if the array is not already sorted).

I think its better to use sort() from the algorithm lib.
C++11 has make the language more rubost and powerful.
I advice all the newbies to have a better grisp of the algorithm lib.

Most of your woes you are facing are all done. Algorithm lib must be your household name.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.