Question

Write a C++ program that would report all of the Min and Max. example: 1. 95...

Write a C++ program that would report all of the Min and Max.

example:
1. 95
2. 95
3. 80
4. 80

lowest 80 on test(s): 3, 4

highest 95 on test(s): 1, 2

I have started it, however, this only outputs one of the Min and Max and not all of the other instances.

#include<iostream>
using namespace std;

int main()
{
 int grades[10] , min , max , minIndex , maxIndex ;    
 int n , choice , rt , fix ;
 int d = 0 ;
 do{
     cout<<"\n\n\nGRADE CENTER\n------------"
         <<"\n1) Enter new grades"
         <<"\n2) Print grades"
         <<"\n3) Print average"
         <<"\n4) Minimum and Maximum "
         <<"\n5) Change a grade"
         <<"\n6) EXIT ";
         
     do{cout<<"\nYour selection? (1-6) ";
         cin>>choice; 
       }while((choice<1)||(choice>6));
     
     if((d==0)&&((choice==2)||(choice==3)||(choice==4)||(choice==5)))
       cout<<"\nNo data entered yet!!";   
     
     if(choice==1)
       {d = 1 ;
        cout<<"\nHow many tests? ";
        cin>> n;
        for(int i=1 ; i<=n; i++)
           {cout<<"\ntest "<< i << " ? ";
            cin>>grades[i]; }
        
      }
    
    if((choice==2)&&(d==1))
       {cout<<"\nGrade Data\n------------";
        for(int i=1 ; i<= n ; i++) 
            cout<<"\ntest "<<i<<" : "<<grades[i];  
       }     
    
    if((choice==3)&&(d==1))
      {rt=0;
       for(int i=1 ; i<=n; i++) rt=rt+grades[i]; 
       cout<<"\nAverage is "<< rt/n ;
      }
         
    if((choice==4)&&(d==1))
      {min = max = grades[1] ;
       minIndex = maxIndex = 1 ;
       for(int i=1 ; i<=n; i++) 
          {if (grades[i]<min) { min=grades[i]; minIndex = i ;}
           if (grades[i]>max) { max=grades[i]; maxIndex = i ;}
          }       
       cout<<"\nLowest was "<< min << " on test " << minIndex
           <<"\nHighest was "<< max << " on test "<< maxIndex  ;
      }
      
    if((choice==5)&&(d==1))
      {cout<<"\nChange test #  ";
       cin>> fix ;
       cout<<"\nChange grade "<<fix<<" from "<<grades[fix]<<" to? ";
       cin>>grades[fix];
       if (grades[fix]<min) { min=grades[fix]; minIndex = fix ;}
       if (grades[fix]>max) { max=grades[fix]; maxIndex = fix ;}
      }
   }while(choice!=6);    
 
 cout<<"\n\n";
 system("pause");
 return 0;
}


Homework Answers

Answer #1
#include <iostream>

using namespace std;

#define SIZE 50

int main()

{
    int array[SIZE];
    int i, max, min, size;
    cout<<"Enter size of the array: ";
    cin>>size;
    cout<<"\n Enter "<<size <<" elements in the array: ";
    for(i=0; i<size; i++)
        cin>>array[i];
    max = array[0];
    min = array[0];
    for(i=1; i<size; i++)
    {
        if(array[i] > max)
            max = array[i];
        if(array[i] < min)
            min = array[i];
    }
    cout<<"\nMaximum element =" << max << "\n";
    cout<<"Minimum element =" << min;
    return 0;

}

c++ program to find minimum and maximum element is give above

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following program allows the user to enter the grades of 10 students in a class...
The following program allows the user to enter the grades of 10 students in a class in an array called grade. In a separate loop, you need to test if a grade is passing or failing, and copy the grade to an array to store passing or failing grades accordingly. A passing grade is a grade greater than or equal to 60. You can assume the use will enter a grade in the range of 0 to 100, inclusive. ...
I need to get the Min and Max value of an array when a user inputs...
I need to get the Min and Max value of an array when a user inputs values into the array. problem is, my Max value is right but my min value is ALWAYS 0. how do i fix this? any help please!!! _________________________________________________________________________________________________ import java.util.Scanner; public class ArrayMenu{ static int count; static Scanner kb = new Scanner(System.in);             public static void main(){ int item=0; int[] numArray=new int[100]; count=0;       while (item !=8){ menu(); item = kb.nextInt();...
Write a C++ program to run a menu-driven program with the following choices: Compute the factorial...
Write a C++ program to run a menu-driven program with the following choices: Compute the factorial of a number Compute the alternating factorial of a number Quit #include <iostream> using namespace std; void getValidUserInputPosNumGT0 (int *a) { int num; cout << "Enter in a positive number greater than 0... "; cin >> *a; } long double factorial (int num) { int fact = 1; while (num > 1) { fact *= num; num--; } return fact; } long double AlternatingFactorial...
USING C++ Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Create your objects in the stack...
USING C++ Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Create your objects in the stack (not on the heap). Add a friend function, kilotopound, which will convert kilograms to pounds. Change your weight mutator to ask whether weight is input in kilograms or pounds. If it is kilograms, call the friend function kilotopound to convert it to pounds and return pounds. There are 2.2 pounds in one kilogram. Create an object on the stack with the following information:     ...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are pointers or constant pointers. Directions: Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS = 3; // may only be declared within the main function string students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Be sure to compile using g++ -std=c++11 helpWithGradesPtr.cpp Write a C++ program to run a menu-driven program with the...
1) Create a flowchart for the program below and Trace the program below with input of...
1) Create a flowchart for the program below and Trace the program below with input of 3 and then again with input of 5. #include <iostream> using namespace std; int Fall(int x, int m) { int Xm = 1, i=x; while(i>=x-m+1) { Xm = Xm*i; i=i-1; } return Xm; } int Delta(int x, int m) { int ans = 0; ans = Fall(x+1,m); ans = ans - Fall(x,m); return ans; } void main() { int x = 0, m =...
1) What do you think the following program will print if you type from the keyboard...
1) What do you think the following program will print if you type from the keyboard the numbers 3 for a and 8 for b ? #include < iostream> using namespace std; int main() { int a, b; cin >> a >> b; if (a > b && b > 7) { if(a < 7) cout << “ a less than 7: “ << a << ‘\n’; else cout << “Else branch executed\n”; return 0; }
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double secondQuizz; double midTerm; double finalTerm; string name; }; int main() { int n; cout<<"enter the number of students"<<endl; cin>>n; struct student students[n]; int i; struct student istudent; for(i=0;i<n;i++) {    cout<<"Student name?"; cin >> istudent.name; cout<<"enter marks in first quizz , second quizz , mid term , final term of student "<<i+1<<endl; cin>>students[i].firstQuizz>>students[i].secondQuizz>>students[i].midTerm>>students[i].finalTerm; } for(i=0;i<n;i++) { double marks=0; double score=students[i].firstQuizz+students[i].secondQuizz+students[i].midTerm+students[i].finalTerm; marks=(students[i].firstQuizz*0.25)+(students[i].secondQuizz*0.25)+(students[i].midTerm*0.25)+(students[i].finalTerm*0.50); double totalArrgegateMarks =...
C ++ program that will read in prices and store them into a two-dimensional array //...
C ++ program that will read in prices and store them into a two-dimensional array // It will print those prices in a table form and the lowest price. // EXAMPLE // Input: // Please input the number of rows from 1 to 10 // 2 // Please input the number of columns from 1 to 10 // 3 // // Input price of item (0,0): 2 // Input price of item (0,1): 4 // Input price of item (0,2):...
Language : C ++ #include #include #include #include #include using namespace std; void DisplayMenu() {   ...
Language : C ++ #include #include #include #include #include using namespace std; void DisplayMenu() {    cout << "1. E games\n";    cout << "2. T games\n";    cout << "3. M games\n";    cout << "4. Total Games\n";    cout << "5. Exit\n"; } double total(double egames, double tgames, double mgames) {    int totalgames = egames + tgames + mgames;    cout << "There are " << totalgames << " games\n";    return totalgames; } double Egames(double egames,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT