KeeganT

Ass65

Oct 15th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     srand(time(NULL));
  10.     int array[30];
  11.     int low=31, high=0, hold=0;
  12.     float total=0, count=0, average=0;
  13.     cout<<"Temperatures for this month: ";
  14.     for(int c=0;c<30;c++)
  15.     {
  16.         array[c]=rand()%30+1;
  17.         count++;
  18.         cout<<array[c]<<", ";
  19.         if(array[c]>high)high=array[c];
  20.         if(array[c]<low)low=array[c];
  21.         total+=array[c];
  22.     }
  23.     cout<<endl;
  24.     cout<<"The highest temperature was: "<<high<<endl;
  25.     cout<<"The lowest temperature was: "<<low<<endl;
  26.     average=total/count;
  27.     cout<<"The average temperature was: "<<average<<endl;
  28.     for(int c=0;c<30;c++)
  29.     {
  30.         for(int x=0;x<29;x++)if(array[x]>array[x+1])
  31.         {
  32.             hold=array[x];
  33.             array[x]=array[x+1];
  34.             array[x+1]=hold;
  35.         }
  36.     }
  37.     cout<<"Numbers in ascending order: ";
  38.     for(int c=0;c<30;c++)cout<<array[c]<<", ";
  39.     for(int c=0;c<30;c++)
  40.     {
  41.         for(int x=0;x<29;x++)if(array[x]<array[x+1])
  42.         {
  43.             hold=array[x];
  44.             array[x]=array[x+1];
  45.             array[x+1]=hold;
  46.         }
  47.     }
  48.     cout<<endl;
  49.     cout<<"Number is descending order: ";
  50.     for(int c=0;c<30;c++)cout<<array[c]<<", ";
  51. }
Add Comment
Please, Sign In to add comment