Hello, i need help finishing my code

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

56 Replies - 1103 Views - Last Post: 16 January 2013 - 03:38 PM Rate Topic: -----

#31 SwiftXShadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 16-January 13

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:35 PM

um i think i found some mistakes i was mixing up i and j few times
Was This Post Helpful? 0
  • +
  • -

#32 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:38 PM

That and seriously - what is up with your forloop conditions?

A for loop is three parts:
1. the loop control variable..
2. Condition to keep looping.
3. the increment/decrement for the loop control variable.

36	for (i=0;i<5;j++)

Why is 'j' being incremented when the lcv is 'i'?

38	for(l=0; l=5; l++)

Why is your condition (to keep looping) 'l=5'? When this starts off the lcv ('l') is zero... when is zero ever equal to five?
Was This Post Helpful? 0
  • +
  • -

#33 SwiftXShadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 16-January 13

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:40 PM

i translated it all into english, the none english words, maybe you better understand then


#include <stdio.h>
#include <time.h>
#include <stdlib.h>



int main (void)



{

int matrix[5] [5];
int first[5];
int i,j,l;



for (i=0;i<5;i++)
{
printf ("enter %d number for the first massive ", i);
scanf ("%d", &first[i]);
}

for (i=0; i<5; i++)
{
    printf("%2d", first[i]);
    
}
printf("\n");





for (i=0;i<5;j++)
{
    for(l=0; l=5; l++)
    {
             printf ("enter %d row and %d column ", i, l);
             scanf ("%d", &matrix[j][l]);
             
    }
}   

for (i=0; i=5; i++)      
{
    for(l=0; l=5; l++);
    {
             printf ("%3d", matrix[j][l]);
    }
}

     printf("\n");
     
     
     
     









scanf ("%d");
return 0;
}



Was This Post Helpful? 0
  • +
  • -

#34 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:44 PM

Translating doesn't stop the other odd errors like these:
46	for (i=0; i=5; i++)     
...
48	for(l=0; l=5; l++);



Your for loop never starts.. because you tell the loop control variables to start at zero.. then you check to see if they are 5.. which they are not.. because you told them to start at zero... so the loop never happens. That's why people tend to use greater than and less than signs (as needed).
Was This Post Helpful? 0
  • +
  • -

#35 SwiftXShadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 16-January 13

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:45 PM

k, i think that all my i and j are fixed propelly now, but now i am back to the endless loop again on the second one

"enter 0 row and 5 column" i can enter as many numbers as i want but it wont go forward form that endlessly gives that
Was This Post Helpful? 0
  • +
  • -

#36 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:47 PM

I have zero idea what you 'fixed'. Are you not getting the pattern that if you change something we need to see it so we know what you changed? I mean we are not sitting over your shoulder so we cannot see what you did/changed/deleted/moved until you post it here.
Was This Post Helpful? 0
  • +
  • -

#37 SwiftXShadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 16-January 13

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:49 PM

ou k, i'll just go saying something dumb again...

for(l=0; l=5; l++); 


i thought the 5 there means the end of it.... so when it reaches 5 it stops.... how did i get my first one working with that logic....

right now it looks like that


#include <stdio.h>
#include <time.h>
#include <stdlib.h>



int main (void)



{

int matrix[5] [5];
int first[5];
int i,j,l;



for (i=0;i<5;i++)
{
printf ("enter %d number for the first massive ", i);
scanf ("%d", &first[i]);
}

for (i=0; i<5; i++)
{
    printf("%2d", first[i]);
    
}
printf("\n");


printf("=========================================================\n");


for (j=0;j<5;j++)
{
    for(l=0; l=5; l++)
    {
             printf ("enter %d row and %d column ", j, l);
             scanf ("%d", &matrix[j][l]);
             
    }
}   

for (j=0; j=5; j++)      
{
    for(l=0; l=5; l++);
    {
             printf ("%3d", matrix[j][l]);
    }
}

     printf("\n");
     
     
     
     









scanf ("%d");
return 0;
}


Was This Post Helpful? 0
  • +
  • -

#38 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:49 PM

Quote

l=5

Look at it.. That conditions say "continue doing the loop when l equals five". It does *NOT* say "continue doing the loop while l is less than five". Less than and equals are two largely different concepts when it comes to loops.

One means 'you *MUST BE* ' and the other is a ceiling/max value.
Was This Post Helpful? 0
  • +
  • -

#39 SwiftXShadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 16-January 13

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:52 PM

right now it looks like this


#include <stdio.h>
#include <time.h>
#include <stdlib.h>



int main (void)



{

int matrix[5] [5];
int first[5];
int i,j,l;



for (i=0;i<5;i++)
{
printf ("enter %d number for the first massive ", i);
scanf ("%d", &first[i]);
}

for (i=0; i<5; i++)
{
    printf("%2d", first[i]);
    
}
printf("\n");


printf("=========================================================\n");


for (j=0;j<5;j++)
{
    for(l=0; l=5; l++)
    {
             printf ("enter %d row and %d column ", j, l);
             scanf ("%d", &matrix[j][l]);
             
    }
}   

for (j=0; j=5; j++)      
{
    for(l=0; l=5; l++);
    {
             printf ("%3d", matrix[j][l]);
    }
}

     printf("\n");
     
     
     
     









scanf ("%d");
return 0;
}



k fixed that...
now how do i make it look like a matrix? with like proper columns.... mine looks like a .... streight line of numbers



#include <stdio.h>
#include <time.h>
#include <stdlib.h>



int main (void)



{

int matrix[5] [5];
int first[5];
int i,j,l;



for (i=0;i<5;i++)
{
printf ("enter %d number for the first massive ", i);
scanf ("%d", &first[i]);
}

for (i=0; i<5; i++)
{
    printf("%2d", first[i]);
    
}
printf("\n");


printf("=========================================================\n");


for (j=0;j<5;j++)
{
    for(l=0; l<5; l++)
    {
             printf ("enter %d row and %d column ", j, l);
             scanf ("%d", &matrix[j][l]);
             
    }
}   

for (j=0; j<5; j++)      
{
    for(l=0; l<5; l++);
    {
             printf ("%3d \n", matrix[j][l]);
    }
}

     printf("\n");
     
     
     
     









scanf ("%d");
return 0;
}



Was This Post Helpful? 0
  • +
  • -

#40 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:55 PM

Maybe - when the iteration for the outer for loop is almost done (and after the iteration of the inner loop) you tell it to print a 'new line' to the screen.
Was This Post Helpful? 0
  • +
  • -

#41 SwiftXShadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 16-January 13

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:56 PM

ummm can u rephrase that, i dont know what the english word "iteration" means
Was This Post Helpful? 0
  • +
  • -

#42 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:57 PM

When the loop processes one of its cycles.
Was This Post Helpful? 0
  • +
  • -

#43 SwiftXShadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 16-January 13

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 03:02 PM

#include <stdio.h>
#include <time.h>
#include <stdlib.h>



int main (void)



{

int matrix[4] [4];
int first[5];
int i,j,l;



for (i=0;i<5;i++)
{
printf ("enter %d number for the first massive ", i);
scanf ("%d", &first[i]);
}

for (i=0; i<5; i++)
{
    printf("%3d ", first[i]);
    
}
printf("\n");


printf("=========================================================\n");


for (j=0;j<4;j++)
{
    for(l=0; l<4; l++)
    {
             printf ("enter %d row and %d column", j, l);
             scanf ("%d", &matrix[j][l]);
             
    }
}   

for (j=0; j<4; j++)      
{
    for(l=0; l<4; l++);
    {
             printf ("%3d\n", matrix[j][l]);
    }
    printf ("\n");
}

    
     printf("\n");
     
     
     
     
     









scanf ("%d");
return 0;
}




like that? it sill looks wrong though...
Was This Post Helpful? 0
  • +
  • -

#44 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 03:03 PM

So what.. you just decided to paste new lines through out your code at random?

Quote

it sill looks wrong though...

Wrong *HOW*?!

Remember this whole pattern thing - you need to explain to us what is going on and that helps us to help you.
Was This Post Helpful? 0
  • +
  • -

#45 SwiftXShadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 16-January 13

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 03:07 PM

umm.... i dunno how to explane....

i entered these numbers
21
3
21
33
22
11
12
31
32
3
21
12
3
21
21
21


and this came out


22
32
3
2686792


where i want it to look normal like

1 2 3 4
2 2 2 2
1 2 2 2
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4