Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:06:58+00:00 2026-06-03T14:06:58+00:00

I have a problem with getting the min,max, and average of an elements of

  • 0

I have a problem with getting the min,max, and average of an elements of 2D array.

I have a 2D array which contains Students and Grades.

I am generating the grades with rand. For example When I enter 2,2 it prints me out

Courses : 01   02   Average   Min   Max
    ID   
    01     8   50     29
    02    74   59     29

, My average function takes the first ones average and doesnt take the others average.

Here is my code ;

int A[30][30];

int findAverage(int noOfStudents ,int noOfGrades ){

    float sum,average;




    for (int i = 0 ; i < noOfGrades ; i++) {
        for (int j = 0; j<noOfStudents; j++) {

        sum += A[i][j];

        }
        average = sum / noOfGrades;
       // cout << "   " << format(average);
        sum = 0;
        return format(average);

    }

and here how I use it

int main() {

    int noOfCourses , noOfStudents;
    cin >> noOfCourses >> noOfStudents;
    cout << "Courses : " ;

    for (int i = 0; i < noOfCourses; i++) {
        if (i+1 >= 10) {

            cout << i+1 << "   ";
        }else{
            cout <<"0" << i+1 << "   ";

        }
    }

    cout << "Average   Min   Max";

    for(int i=0; i<noOfStudents; i++) {         //This loops on the rows.        

        for(int j=0; j<noOfCourses; j++) {     //This loops on the columns
            A[i][j] = genGrade(); 
        }
    }

    cout << "\n    ID   " << endl;

    for(int i=0; i<noOfStudents; i++) {  //This loops on the rows.

        if (i+1 >= 10) {

            cout <<"    " << i+1 << "   ";
        }else{
            cout <<"    0" << i+1 << "   ";

        }

        //cout <<"    0" << i+1 << "   ";

        for(int j=0; j<noOfCourses; j++) {  //This loops on the columns


            if (A[i][j] >= 10 && A[i][j] <=99) {

                cout <<" " << A[i][j]  << "  ";
            }
            if(A[i][j] < 10) {

                cout <<"  " << A[i][j] << "  ";
            }
            if (A[i][j] == 100) {

                cout << A[i][j] << "  ";
            }
        }
        cout <<"   "<<findAverage(noOfStudents,noOfCourses);
        cout << endl;
    }
}

What am I doing wrong ? Also How could I get the min,max of the per array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:06:59+00:00Added an answer on June 3, 2026 at 2:06 pm

    The problem is that in your findAverage function you have a return statement within the loop that is looping through the rows. If you want a very simple fix add another parameter to the findAverage function that indicates which row to calculate the average for.

    int findAverage(int course ,int noOfGrades ){
    
        float sum,average;
    
    
        for (int j = 0; j<noOfStudents; j++) {
    
            sum += A[course][j];
    
        }
        average = sum / noOfGrades;
        return format(average);
     }
    

    and call it like this

    cout <<"   "<<findAverage(i,noOfCourses);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div which contains 2 child elements. The 1st div have content
I just started a graphical C++ course and I have problem getting an overview
I have a problem getting the right Price for a product based on Effectivity
I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the
I have a problem getting a private method using reflection. Even with BindingFlags.NonPublic and
I have this problem getting my newly created php project on Netbeans work on
I have a problem with getting my pager-function to work. For some reason it
I have a problem with getting jquery to retrieve results from a WCF service.
I have a problem with getting a class from an external .jar file. I
I seem to have a problem with getting MVC to fill in my custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.