so im trying to find the min, max, range, mean, median, and mode. The max number is right but the min isnt. Once that is corrected, i can get range and mean easily. Also, i have no idea how to get mode and median. Im guessing the values in the arr2 would have to be sorted. Any thoughts? Id appreciate it.
This refers to the values in arr2 which are the calculated values in the formula. You can enter -2 and 2 for userMin and userMax.

    #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;

       double total = 0;
       double mn=arr2[0];
       double mx=arr2[0];
       float range;
       float median;
       float mode;


       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;
             total += arr2[e];

             count++;
             x = userMin + inc*count;
             if (mn > arr2[e])
             {
                mn = arr2[e];
             }

             if (mx < arr2[e])
             {
                mx = arr2[e];
             }



          }
       }

       cout << endl;
       cout << "min " << mn << endl;
       cout << "max " << mx << endl;
       //cout << "mode" << mode << endl;
       //cout << "median " << median << endl;
       cout << "mean " << total / SIZE << endl;
       cout << "range " << mx - mn << endl;
       return 0;
    }

Tell me, after line 26 and 27 executes, what values do mn and mx have?

thats where the minimum and maximum are suppposed to be

No, I asked what those values are, at the start; not what values you hope they will be at the end. Because on line 46 and 51 you're going to start using those values. You're making comparisons of those values. So what are their starting values? The very first time, when you do this,

if (mx < arr2[e])

what value does mx have? If it had the value of, say, 50 billion, would that be a problem?

ok so mn and mx in if(mx<arr2[e]) and if(mn>arr2[e]) will have the value of the first element in the array right?

will have the value of the first element in the array right?

And what is that number? Is it a million? If it's a million, then mx will be a million and this condition mx<arr2[e] will never be true. So is it a million?

If you think it's not a million, what is it? You set the value of mx on line 26. What number did you set it to? What actual number? Is it zero? Is it one? Is it two?

well it depends on the range the user puts, so lets go with -2 and 2. arr[e] hold the values from -2 and 2 while arr2[e] holds the values after being calculated for each number from -2 and 2 so arr2[0] would hold (0.0572cos(4.667(-2)) + 0.0218cos(12.22(-2))) which is -0.040. Is this what youre asking?

You created an array on line 16. The array you created is named arr2, and it is composed of 21 int values. The value of arr2[0] is random. It could be anything. You didn't set it, so it could be absolutely anything at all.

On line 27, you then make mx equal to that random number. So mx could be anything. Anything at all. If it's bigger than the largest value that you end up actually comparing it to, then it will never change.

oh ok i see what you mean now, so how can i fix this? is it something like making mx equal to something like -2000 and mn to 2000 for example?

wow i guess that was it, thanks for helping

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.