hi
i am new here and i registered because i couldn't find the answer in google search
my problem is that i could not find max and min of two arrays and the average too

#include<iostream>
using namespace std;
int array1[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int array2[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int a;
int print_menu()
{            
    int choice;
    cout<<"#----------------------------------\n";
    cout<<"# Manipulation of arrays          #\n";
    cout<<"#                                 #\n";
    cout<<"# BY MAFD                         #\n";
    cout<<"#----------------------------------\n";
    cout<<"# 1. Read Array 1                 #\n# 2. Read Array 2                 #\n";
    cout<<"# 3. Max_min_two_arrays           #\n# 4. sum_two_arrays               #\n";
    cout<<"# 5. Average_two_arrays           #\n# 6. Quit                         #\n";
    cout<<"#----------------------------------\n";
    cout<<"# Enter your Choice (1-6) :";
    cin>>choice;
    
    return choice;
    }
    void print_array(int[],int)
    {int number;
     cout<<"\nInitialization Of Array "<<a<<endl;
         for (int i=1 ; i<=10 ; i++){
         cout<<"Enter integer "<<i<<" : ";
         cin>>number;
         array1[i]= number;}
         }
     void read_array(int[],int)
     {cout<<"\n\nContent of array "<<a<<" : ";
         for (int i=1 ; i<=10 ; i++)
         cout<<array1[i]<<" ";
         cout<<"\n-------------------------\n";
         }
     void max_min_two_arrays(int[],int[])
     {  
        int max=array1[0]; 
        int min=array1[0]; 
        cout<<"\n\nContent of array 1 : \n";
        cout<<array1<<endl;
     
        for (int i=1 ; i<=10 ; i++)
        {if (array1[i]>max)
        {
        max=array1[i];
        }
        else if (array1[i]<min)
        {
        min=array1[i];     
        }
        }
        }
        
            
int main(){
   int choice; 
   do{
    
    system("cls");
    choice = print_menu();      
    
    switch (choice){
    case 1 :
         a=1;
         print_array(array1,1);
         read_array(array1,1);
         break;
     case 2 :
         a=2;
         print_array(array2,2);
         read_array(array2,2);
         break;
     case 3 :
         max_min_two_arrays; 
         break; 
     case 6 :
         cout<<"\nThanks and by... MAFD\n"<<endl;
         break;
         default:
         cout<<"*** Error: The choice must be 1 to 6 \n";  
         }
         system("pause");
         }
         while(choice!=6);
   
   return 0;
    }

I see two major problems with the min/max code as it is now. First, when you attempt to call the function max_min_two_arrays , you did not give it's arguments; as a result, the function isn't actually getting called (it simpley returns the pointer to the function, which, since nothing is assigned on that line, goes into the ether), so the line of code doesn't have any effect.

The second is that, in the function itself, once you get the max and min values, you don't do anything with them.

Your i variable you use in your for loops should not exceed 9:

for(int i = 1; i < 10; i++)   // Not i <= 10 !
// ...
cout<<"\n\nContent of array 1 : \n";
cout<<array1<<endl;

This won't work. Print each value seperately instead, using again a for loop.

thank you Schoil-R-LEA and mikrosfoititis for trying to help me

but i fix the problem using this way

int min1,max1,max2,min2;
        int i;
 
       for(i=0;i<10;i++)
       {
       array1[i];
       }
       min1=array1[0];
       max1=array1[0];
       for(int i=0;i<10;i++)
	   {
	   if(min1>array1[i])
	   {
        min1=array1[i];
       }
       else if(max1<array1[i])
	   {
	    max1 = array1[i];
	   }
	}
      for(i=0;i<10;i++)
      {
       array2[i];
      }
      min2=array2[0];
      max2=array2[0];
      for(int i=0;i<10;i++)
	  {
      if(min2>array2[i])
      {
      min2=array2[i];
      }
      else if(max2<array2[i])
      {
      max2 = array2[i];
      }
  }  
    if(max1>max2)
    cout<<"\nMax_of_the_two_arrays = "<<max1<<endl;
    else
    cout<<"\nMax_of_the_two_arrays = "<<max2<< endl;
    if(min1<min2)
    cout<<"Min_of_the_two_arrays = "<<min1<<endl<<endl;
    else
    cout<<"Min_of_the_two_arrays = "<<min2<<endl<<endl;

but is there another way to solve it more Professionalism :)

and thanks

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.