not printing

sorry guys but i have a new problem...my program isn't printing out anything i dont know what to do. Please help.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* This program uses multidimensional arrays to find the largest
* number compared to their neighbors. I call this program ne.c */

#include <stdio.h>    /* librarys */
#include "genlib.h"

#define size 5 /* constants */

void displayMatrix(int ne [size][size]);
int main()
{
/* the ne values you may change them if you wish */
int ne[size][size]=
{
   {1,0,1,0,1}, /* if you are going to change the values please change the values on the inside not the outside */
   {0,9,5,2,0}, 
   {1,12,8,3,1},
   {0,4,7,12,0},
   {1,0,1,0,1}
};
displayMatrix(ne);
return 0;  
}
void displayMatrix(int ne [size][size])
{
int i, j, m, n;
m = 1;
n = 2;
for (m=1;m<=6;m++)
{
while (n<=6)
{
for (i=0;i<=6;i++)
{
while (j<=6)
{
if (ne[i, j] > ne[m, n]==true)
{
printf("%d in location (%d, %d)\n", ne[i, j], i, j);
}
if (n==5 && m==5)
{
break;
}
if (i==5)
{
i=0;
j+=1;
}
if (n==5)
{
n=0;
m+=1;
}
}
}
}
}
getchar();
}
There is no indentation in your code, could you fix that please?
im not sure i understand. please clarify.
He means that all your code is up against the damn margin, which means we can't tell what the scope of the curly brackets is. Have you never used an IDE? Assuming you have, you've surely seen the tabs at the sides to push out scopes. Do that. Otherwise the code is illegible and will only confuse every poor sap who has to burn their eyes looking at it.
Dammit, I hate seeing illegible code. It happens so much.
Last edited on
ok here is the program with tabs

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* This program uses multidimensional arrays to find the largest
* number compared to their neighbors. I call this program ne.c */

#include <stdio.h>    /* librarys */
#include "genlib.h"

#define size 5 /* constants */

void displayMatrix(int ne [size][size]);
int main()
{
/* the ne values you may change them if you wish */
int ne[size][size]=
{
   {1,0,1,0,1}, /* if you are going to change the values please change the values on the inside not the outside */
   {0,9,5,2,0}, 
   {1,12,8,3,1},
   {0,4,7,12,0},
   {1,0,1,0,1}
};
displayMatrix(ne);
return 0;  
}
void displayMatrix(int ne [size][size])
{
     int i, j, m, n;
     m = 1;
       n = 2;
         for (m=1;m<=6;m++)
             {
             while (n<=6)
             {
             for (i=0;i<=6;i++)
             {
             while (j<=6)
             {
             if (ne[i, j] > ne[m, n]==true)
             {
             printf("%d in location (%d, %d)\n", ne[i, j], i, j);
             }
             if (n==5 && m==5)
             {
             break;
              }
              if (i==5)
              {
               i=0;
               j+=1;
                }
                 if (n==5)
                  {
                   n=0;
                     m+=1;
                       }
                          }
                           }
                             }
                              }
                               getchar();
                               } 
NO.
You are supposed to put tabs as the scope increases and then tab it back. Here is what a program with tabs looks like:
1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
    // TABBED OUT, THE SCOPE IS IN MAIN
    int x = 0;
    if (x == 0)
    { // TABBED OUT AGAIN, THE SCOPE IS IN THE IF
         for (x = 0; x < 4, x++)
         { // TABBED OUT AGAIN, THE SCOPE IS IN THE FOR
              cout << "TAB IT DAMMIT ";
         }
    } // THE TABS GO BACK AS THE SCOPES THEY CORRESPOND TO END
}


You don't just wantonly throw in tabs as the code goes down.
Use an IDE and take a look at what happens every time you type a new pair of curly brackets. You'll see what happens. And I personally refuse to provide any program diagnosis until you've tabbed it suitably. The disaster you just posted is an aberration of nature so twisted that no human eye should be subjected to it. It was worse than your first post.
Last edited on
Indentation ought to be a requirement of the programming language. That would make disaster formatting less prevalent.
ok i rewrote my program with tabs I hope this is correct

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include "genlib.h"

#define size 5

void displaymatrix(int ne[size][size);
int main()
{
    int ne[size][size]=
    {
        {1,0,1,0,1},
        {0,9,6,7,0},
        {0,4,8,6,0},
        {0,7,4,5,0},
        {0,1,0,1,0}
        };
        displaymatrix(ne);
        return 0;
}
void displaymatrix(int ne[size][size])
{
     int i, j, m, n;
     m=1;
     n=2;
     for (m=1; m<=6; m++)
     {
         while (n<=6)
         {
               for (i=0;i<=6;i++)
               {
                   while (j<=6)
                   {
                         if (ne[i, j] > ne[m, n]==true)
                         {
                                   printf("%d in location (%d, %d)\n", ne[i, j], i, j);
                                   }
                                   if (n==5 && m==5)
                                   {
                                            break;
                                   }
                                            if (i==5)
                                            {
                                                     i=0;
                                                     j+=1;
                                            }
                                                     if (n==5)
                                                     {
                                                              n=0;
                                                              m+=1;
                                                     }
                         }
                   }
               }
         }
     }
getchar();
}
Last edited on
Im sorry for me its easier to read code without indentation.
Those are some big tabs although they are legible. However you misinterpret again. You should only tab out again if you have a new scope.
I'm getting seriously annoyed by this but I'll indent the code for you. Whether or not you can read it easier without (which should not even be possible, what planet are you from?), you HAVE to indent properly or people have the right - responsibility - to ignore you for the sheer illegibility of the crap you throw between the tags.
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include "genlib.h"

#define size 5

void displaymatrix(int ne[size][size);
int main()
{
    int ne[size][size]=
    {
        {1,0,1,0,1},
        {0,9,6,7,0},
        {0,4,8,6,0},
        {0,7,4,5,0},
        {0,1,0,1,0}
    };
    displaymatrix(ne);
    return 0;
}
void displaymatrix(int ne[size][size])
{
     int i, j, m, n;
     m=1;
     n=2;
     for (m=1; m<=6; m++)
     {
         while (n<=6)
         {
               for (i=0;i<=6;i++)
               {
                   while (j<=6)
                   {
                         if (ne[i, j] > ne[m, n]==true)
                         {
                              printf("%d in location (%d, %d)\n", ne[i, j], i, j);
                         } // DO NOT EXTEND AGAIN HERE, THE SCOPE ENDS SO GO *BACK*
                         if (n==5 && m==5)
                         {
                               break;
                         }
                         if (i==5)
                         {
                               i=0;
                               j+=1;
                         }
                         if (n==5)
                         {
                               n=0;
                               m+=1;
                         }
                   }
              }
         }
     }
     getchar();
}


Note that I removed one curly bracket because it was extraneous. That was a real task, someone correct me if I caused any syntax errors.
You don't deserve any more of my help. Ask someone who didn't go through that house of horrors.
Last edited on
ok. ill start a new thread this thread is too long people will have to do a lot of scrolling
I hope my pains have shown you how code is supposed to look. Because I'm never doing that ever again. It was horrible... :)
Indentation ought to be a requirement of the programming language. That would make disaster formatting less prevalent.
FIOC is one of the most horrible abortions spat into this or any other world.
I believe that's the nastiest thing I've ever said about anything.
Worse than the post with the horrible misindented code?
Yes. The programmer should be entirely free to give his code whatever shape he so desires. He shouldn't be subject to the whims of the language designer.
If that means that atrocities such as the one above will occur, so be it.
Last edited on
I suppose. But it should at least be an expectation, if it isn't already. It's the code itself that should be art, not the shape it's presented in.
Last edited on
thank you helios. programs are based on correctness, user interface, documentation, design and efficiency.
helios wouldn't like Python
I see why...
Topic archived. No new replies allowed.