In this program:
1) an integer typed 2D array named student_scores[Rows][Cols] is initialized by providing initialization list
2) then this array is passed to a function named total_scores which recevies two aurguments
.- the first aurgument is for array with explicit use of column subscript
.- the second one is row size
.- e.g int total_scores(const int [][Cols], int);
3) in the funciton definition, the function sums all the contents/ scores of arrays into an integer type variable named int total
4) then the total is shown by calling this funciton in the main() function with cout statement as:
cout<<"Total of all the values in student_scores[][]: "
<<total_scores(student_scores, Rows);
5) here it is ok
** 6) But when i compile this program, the compiler generates an error something like that
in function main:
[Linker error] undefined reference to 'total_socres(int const[][3], int)'
id returned 1 exit status
thus the problem is
** 1) why this error occours while i have provided the function definition
** 2) how to resolve this error in order to run this program**
#include<iostream>
#include<conio.h>
using namespace std;
const int Rows=3;
const int Cols=3;
int total_scores(const int [][Cols], int);
main()
{
int student_scores[Rows][Cols]={ {1,3,5},
{2,4},
{4,5,6}};
cout<<"Total of all the values in student_scores[][]: "
<<total_scores(student_scores, Rows);
getch();
}
int total_socres(const int array[][Cols], int Rows)
{
int total =0;
for(int i=0; i < Rows; i++ )
{
for(int j=0; j<Cols; j++)
{
total = total+array [Rows][Cols];
}
}
return total;
}
irtza 0 Newbie Poster
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.