0

I'm doing a task, and I'm having some problems, so help please, u kind people :D I need to create function that allows input for student grades. In that function, I need to allow only input for 6-10 (passing grades). Then, I need to make a function that calculates lowest grade for student. And, in the end, need to make a function that calculates average grade per student. PS : Maybe my ideas are wrong, or u would to something different or better, say it please, I wanna learn. Thanks in advance.

Here is my code and errors :

#include <iostream>
using namespace std;
int input (int [][4], int);
int average (int [][4], int);
int min (int [][4], int);
int main ()
{
 const int wdth = 5;
 int matrix[4][4];
 input (matrix [4][4], wdth);
 average (matrix [4][4], wdth);
 min (matrix [4][4], wdth);
return 0;
}
int input (int matrix[][4], int wdth)
{
 for (int i = 0; i < wdth; i ++)
 {
 cout<<"Enter grades for "<<i+1<<" student:"<<endl;
 for (int j = 0; j < wdth; j ++)
 {
 cin>>matrix[i][j];
 if ((matrix[i][j] < 6) || (matrix[i][j] > 10))
 {
 cout<<"INVALID INPUT!"<<endl;
 return 0;
 }
 //cout<<setw(5);
 cout<<matrix[i][j];
 }
 cout<<endl;
 }
 return 0;
}
int average (int matrix[][4], int wdth)
{
 int sum = 0;
 int avrg = 0;
 for (int i = 0; i < wdth; i ++)
 {
 cout<<"Calculating average for "<<i+1<<" student: "<<endl;
 for (int j = 0; j < wdth; j ++)
 {
 sum = sum + matrix[i][j];
 }
 }
 avrg = sum / 5;
 return 0;
}
int min (int matrix[][4], int wdth)
{
 int temp = 0;
 int MIN = 10;
 for (int i = 0; i < wdth; i ++)
 {
 cout<<"Calculating lowest grade for "<<i+1<<" student: "<<endl;
 for (int j = 0; j < wdth; j ++)
 {
 temp = matrix[i][j];
 if (temp < MIN)
 {
 MIN = temp;
 }
 }
 cout<<MIN;
 }
 return 0;
}

ERRORS:

cpp(11) : error C2664: 'input' : cannot convert parameter 1 from 'int' to 'int [][4]'
 Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
cpp(12) : error C2664: 'average' : cannot convert parameter 1 from 'int' to 'int [][4]'
 Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Naveen
73.9k47 gold badges182 silver badges237 bronze badges
asked Feb 28, 2011 at 10:20

2 Answers 2

5

input (matrix [4][4], wdth); Here matrix [4][4] is an element of the matrix i.e. an int. You need to do input(matrix,wdth);

answered Feb 28, 2011 at 10:24
Sign up to request clarification or add additional context in comments.

Comments

3
input (matrix [4][4], wdth);
average (matrix [4][4], wdth);
min (matrix [4][4], wdth);

Try it this way. :)

input (matrix, wdth);
average (matrix, wdth);
min (matrix, wdth);

With matrix[4][4] your passing the 4th element of the 4th row. ;)

answered Feb 28, 2011 at 10:24

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.