1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

i want a emrgency help in c++

Discussion in 'C++' started by sosoty, Jan 18, 2010.

  1. sosoty

    sosoty New Member

    Joined:
    Jan 18, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    write a c++ program that: reads up to 20 floating pint numbers from standard input into an arrays first then< after numbers are stored in the arrays
    which will calculate the max., min. and average values of the numbers in the arrays.



    CAn any one help me in this naw ? :embarasse
     
  2. kiddo

    kiddo New Member

    Joined:
    Apr 11, 2009
    Messages:
    65
    Likes Received:
    1
    Trophy Points:
    0
    Code:
    #include <iostream>
    using namespace std;
    
    int n = 20;
    float data[n];          // Declare an array with float type (max index = 20)
    
    void inputArr();       // Input data to Array
    float findMax();       // Find the maximum value
    float findMin();        // Find the minimum value
    float findMean();     // Find the average
    
    int main(){
      inputArr();
      cout << "Min\t: " << findMin() << endl;
      cout << "Max\t: " << findMax() << endl;
      cout << "Mean\t: " << findMean() << endl;
      system("pause");
      return 0;
    }
    
    void inputArr(){
      system("cls");
      cout << "Input Array Data" << endl;
      cout << "===========" << endl;
      for (int i=0; i<n; i++){
        cout << "data-" << (i+1) << " : ";
        cin >> data[i];
      }
      system("pause"); 
    }
    
    float findMin(){
      float min = data[0];
      for(int i=1; i<n; i++){
        if(min > data[i]){
          min = data[i];
        }
      }
      return min;
    }
    
    float findMax(){
      float max = data[0];
      for(int i=1; i<n; i++){
        if(max < data[i]){
          max = data[i];
        }
      }
      return max;
    }
    
    float findMean(){
      float total = 0;
      for(int i=0; i<n; i++){
        total += data[i];
      }
      return total/n;
    }
     
    Last edited: Jan 22, 2010
    shabbir likes this.
  3. sosoty

    sosoty New Member

    Joined:
    Jan 18, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    kidoo thank you v.much

    wish if can help you in future as you did :nice:
     
  4. kiddo

    kiddo New Member

    Joined:
    Apr 11, 2009
    Messages:
    65
    Likes Received:
    1
    Trophy Points:
    0
    No prob.
    Is it a school or your lecturer assignment?
     

Share This Page