Please help

I have this program, this is giving junk/garbage values in output:
Statement: take input from user in first 3 columns of each row.add these 3 columns and print out on 4th column and check weather number is even or odd, if even place 0 on 5th column.
sorry for my english.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <cstdlib> 
using namespace std;
int main() {
int a[5][5], i, j, sum, k, l, f, x;
for(i=0;i<3;i++)
{
 for(j=0;j<3;j++)
 {
  cout<< "Enter the value of A [" << i << "][" <<j << "] :-";
 cin >> a[i][j];               
  }             
 }
  
  for(k=0;k<3;k++)
  {
   for(l=3;l<4;l++)
   {
   sum=a[i][0]+a[i][1]+a[i][2];
   a[k][l]=sum;                
                   }}
   for(k=0;k<3;k++)
  {
   for(l=4;l<5;l++)
   {
       if(a[k][l]%2==0)
       x=a[k][l];            
                   }}                  
for(i=0;i<4;i++)
{for(j=0;j<4;j++){
  cout<< "   " <<a[i][j] << "   " << a[k][l] << "   " << x;;                
                
                }cout<<"\n";}
       system("Pause");  system("CLS");       }
                   
    
    
    
    
   
@ammar9493

You have a few problems with your program, and it's not doing what you think you're trying to do.

Here's a corrected version, with remarks, explaining what's happening.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
#include <cstdlib> 

using namespace std;

int main()
{
 int a[5][5], i, j, sum, k, l;
 for(i=0;i<3;i++)
 {
	for(j=0;j<3;j++)
	{
	 cout<< "Enter the value of A [" << i << "][" <<j << "] :-";
	 cin >> a[i][j];               
	}             
 }

 for(k=0;k<3;k++)
 {
		 sum=a[k][0]+a[k][1]+a[k][2]; // sum equals first three array values
	 a[k][3]=sum; // Assign sum to 4th place in array               
	}
 for(k=0;k<3;k++)
 {
	 if(a[k][3]%2==0)
		a[k][4] = 0;// Assign a 0, if even, in 5th place
else
    a[k][4] = 1; // if not even, assign a 1, in 5th place    
	} 

cout << "Column 1      Column 2      Column 3      The Totals     Odd = 1 / Even = 0" << endl;                   
 for(i=0;i<3;i++)
 {
		 cout<< "   " <<a[i][0] << "\t\t " <<a[i][1] << "\t\t " <<a[i][2] << "\t\t " << a[i][3] << "\t\t "<<a[i][4] << endl; 
// Print out each array values, under the appropriate headings              
 }
 system("Pause");
 system("CLS"); 
}
Topic archived. No new replies allowed.