2dimension array

im a begginer with this kind of program can you help me how to use the 2d array in c++...because i dont know how to make program in 2d array...this would be the output...

MIDTREM GRADE
//input 5 int
[1] 90
[2] 99
[3] 98
[4] 99
[5] 89
FINAL GRADE
//input again 5 int
[1] 87
[2] 88
[3] 78
[4] 99
[5] 98

//then the output would be the
[1] 90 87
[2] 99 88
[3] 98 78
[4] 99 99
[5] 89 98


//end of program...
please help me... hope somebody help me with this problem
wat would be the program that i must use..?
Last edited on
My guess is that you don't need to use a 2D array for this. You could define a struct like this:

1
2
3
4
5
struct Grade
{
    int mid;
    int fin;
};

and then make an array of such structs, like this:

Grade grades[5];

Info on structs -> http://cplusplus.com/doc/tutorial/structures/
Info on arrays -> http://cplusplus.com/doc/tutorial/arrays/

However, if you have to use a 2D array, you will find the info you need in the second link above.
Last edited on
do you want my help i can definitely do it...
@ god. "Only help those who help themselves."
Initialize two one dim arrays so that each array has one data set.
Use a for loop to print a[i]" "b[i] "\n"; with an ending condition of i<5;
......or must you use a two dim array to solve?
ok cnoeval...
@jhen try making a 2d array like this: arrayA[index] and arrayB[index];
then you will use a nested for loop a loop within a loop... well the algorithm goes like this... the loop goes by column... and the outer loop will determine the column and the inner loop will input for the rest of the index inside the said column right???? jah get it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main()
{
    int midterm[5] ;
    int final[5] ;
    for(int i=1 ; i<=5 ; i++)
    {   cout << "Enter " << i << ". Midterm Grade" << endl ;
        cin >> midterm[i] ;
        }
        
        for(int m=1 ; m<=5 ; m++)
    {   cout << "Enter " << m << ". Final Grade" << endl ;
        cin >> final[m] ;
        }
        
        for(int k=1 ; k<=5 ; k++)
    {   cout << midterm[k] << " " ; 
        cout << final[k] << endl ;
        }        
    
                
    system("PAUSE") ;
}

Here is the code. Dont forget to change Return value if you do not use Dev C++ ;)
Last edited on
you know what thanks for that info now i know it....thanks guys!!!


you know what thanks for that info now i know it....thanks guys!!!

now guys could you help me again on how to make a program of COUNTRY code like updating and declaring new value on it....i dont really yet understand the process of array thats why i dont know how to use it....
thanks=))
Topic archived. No new replies allowed.