Hello, i need help finishing my code

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

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

#16 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 - 12:35 PM

I erased the wrong code, but then i axidently activated it and sow something wierd.
at top i have written int nTotal = 0;
which means nTotal is 0 right?
and at bottom
printf ("%d", nTotal);
which is the code to put it on screen rgiht?... but it keeps giving me random numbers insead, that look as if they could be the sums of a column... but that dosnt make sence the only code i have for that is that it is 0????

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

#define RIDU 4
#define VEERGE 7
#define MAX 15
#define MIN 10

int main (void)


{
	
	

int maatriks [RIDU] [VEERGE];
int i,j;
int nTotal = 0;

srand(time(NULL));



for(i=0; i<RIDU; i++)

{
for(j=0; j<VEERGE; j++)
{

maatriks[i][j]=rand()%(MAX-MIN)+MIN;
}
}



printf("Genereeritud matrix on:\n\n");

for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
 printf("%4d", maatriks[i][j]);
}
printf("\n\n");
}


printf("========================================\n");
printf("Kolmandast tulbast paremale jäävad tulbad\n");

for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
 
 if (j>2)  printf("%4d", maatriks[i][j]);
}
printf("\n");
}
printf("========================================\n");


for(i=0; i<RIDU; i++)
{
    nTotal += maatriks[i][2];
}


printf("neljas tulp ja selle arvude summad\n");

for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
	        
 if (j<1)  printf("%4d", maatriks[i][3]);
}
printf("\n");
}
printf("----------------------------------------\n");

printf("viies tulp ja selle arvude summad\n");

for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
 if (j<1)  printf("%4d", maatriks[i][4]);
}
printf("\n");
}
printf("----------------------------------------\n");

printf("kuues tulp ja selle arvude summad\n");

for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
 if (j<1)  printf("%4d", maatriks[i][5]);
}
printf("\n");
}
printf("----------------------------------------\n");

printf("seitsmes tulp ja selle arvude summad\n");

for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
	
 if (j<1)  printf("%4d", maatriks[i][6]);
}
printf("\n");
}
printf("----------------------------------------\n");



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



printf ("%d", nTotal);

scanf ("%d");











return 0;
}



This post has been edited by jimblumberg: 16 January 2013 - 12:44 PM
Reason for edit:: Fixed Code Tags.

Was This Post Helpful? 0
  • +
  • -

#17 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 - 12:41 PM

umm...... and i dont know why i coulnt get the code into the code format....
Was This Post Helpful? 0
  • +
  • -

#18 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 - 01:06 PM

Also what does it mean to have an array be entered by keyboard? (it is an other exercise i have, one of the requirements in it i dont understand.

Does that mean that the programs user enters the numbers of the array?
Was This Post Helpful? 0
  • +
  • -

#19 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 - 01:08 PM

I would take that as the user is asked to provide a number, the app reads in the key, enters it into an array, and asks again.. it repeats this until either the array max is reached or the user types in the character designated as 'break out of this loop'.
Was This Post Helpful? 0
  • +
  • -

#20 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 - 01:28 PM

why is it i type 2 lines.... and it is already hoplessly broken?
i type that little bit and i get 20 errors? why? i dont even understand half the things the errors say. The only error i agree with is the last one saying, "confused by earlyer errors"

3:2 C:\Users\SwiftXShadow\Desktop\koondtoo2.c invalid preprocessing directive #inculde
C:\Users\SwiftXShadow\Desktop\koondtoo2.c In function `main':
13 C:\Users\SwiftXShadow\Desktop\koondtoo2.c [Warning] excess elements in array initializer
13 C:\Users\SwiftXShadow\Desktop\koondtoo2.c [Warning] (near initialization for `massiiv')

what do all the errors mean? i dont understand a single one what it is trying to say.

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



int main (void)



{
int massiiv[2] = {a,b,c};
int a,c,b;








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



k i found 1 that was broken and fixed then #include <stdlib.h> taht took the first error away, what about the 3 others? i bearly wrote ANYTHING... and it is full... of errors
Was This Post Helpful? 0
  • +
  • -

#21 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 - 01:35 PM

look at your code and reason it out.

12	int massiiv[2] = {a,b,c};
13	int a,c,b;



The first thing comes to mind - you are telling the array to be a size of 2... but trying to assign three elements to it. Does it make sense to say "hey.. you can only carry two things, but I am going to give you three!"?

The second issue is a, b, c. You declare them (tell the compiler - "Hey! I want some memory for these three variables!") *AFTER* you tried using them. Does it make sense to say "Hey - I want you to hold these three mystery objects... *pause* *pause**pause* they are flaming robopirannah!". No. You need to declare variables first and *THEN* use them.


edit:

Quote

excess elements in array initializer

What do those words mean?

Excess

Quote

the fact of exceeding something else in amount or degree: His strength is in excess of yours.

http://dictionary.re...owse/excess?s=t

"elements in array" - the individual parts that make up an array collection.

"array initializer" - look at where you declare you array.


Put it all together - you have too many damn things trying to be shoved into your array when the array is being initialized/created.

edit edit:
Ultimately you need to calm down, take a lap, have some dip, shoot some hoops, and get some air.. and then come back to this. Stop the panic attacks.

This post has been edited by modi123_1: 16 January 2013 - 01:39 PM

Was This Post Helpful? 0
  • +
  • -

#22 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 - 01:41 PM

but doesnt computer read 0,1,2? so if i put 2 it is 0,1,2?
Was This Post Helpful? 0
  • +
  • -

#23 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 - 01:44 PM

No. When you tell an array you are size of 2 that means you have two elements.. combine that with arrays start counting their indexes at 0 that means you have index 0, and 1.

If you want an index 2 you need to tell your array you want it to be size 3.
Was This Post Helpful? 0
  • +
  • -

#24 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 - 01:44 PM

get some AIR? i have to send it in exactly 1 hour and 10 mins , i spent most of my time trying to feagure out how to sum up the colums which i never manuaged to do. So in that time i gotta finish what ever i still can of the other program, and the hell trying to feagure out how to sum them cuz i dont have time to search or read how anymore.
Was This Post Helpful? 0
  • +
  • -

#25 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 - 01:48 PM

Yes.. get some air. It's amazing what five minutes of being away from the problem does. Typically I go stroll around the building, shoot a few free throws with the (convenient) youth outside, or throw the clackity-clack in the alley for beer money. Five minutes later I am inside, energized, my brain had time to take a break as well, I am typically out of my mental rut that would have destroyed me, and I can attack the problem with renewed vigor.
Was This Post Helpful? 1
  • +
  • -

#26 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1335
  • View blog
  • Posts: 4,575
  • Joined: 19-February 09

Re: Hello, i need help finishing my code

Posted 16 January 2013 - 02:15 PM

You are summing a column :

064	for(i=0; i<RIDU; i++)
065	{
066	    nTotal += maatriks[i][2];
067	}




 nTotal += maatriks[i][2];
  
 /* is equivalent to */
 nTotal = nTotal + maatriks[i][2];




You are summing the third column ([2]) there.

You could create separate total variables for each column, eg nTotalThirdColSum.
Was This Post Helpful? 0
  • +
  • -

#27 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:28 PM

why does my first.... matrix... well... it isnt really a matrix it only has 1 row... well why does my first what ever u call it work, but my second matrix dosnt?



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



int main (void)



{

int maatriks[5] [5];
int esimene[5];
int i,j,l;



for (i=0;i<5;i++)
{
printf ("sisesta %d arv esimese mssiivi jaoks ", i);
scanf ("%d", &esimene[i]);
}

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



for (i=0;i<5;j++)
{
    for(l=0; l=5; l++)
    {
             printf ("sisesta %d rida ja %d veerg ", i, l);
             scanf ("%d", &maatriks[i][l]);
             
    }
}   

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

     printf("\n");
     
     
     
     









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




[code/]

crap, i messed up my 
again... put slash wrong side...

crap, i messed up my [/code] again... put slash wrong side...

i just realized...... do u people still understand even though the words are in a forein language to you? do i need to translate?
Was This Post Helpful? 0
  • +
  • -

#28 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:28 PM

Explain "doesn't work" and what, in all that code, is your "second matrix".
Was This Post Helpful? 0
  • +
  • -

#29 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:33 PM

well the second on basically....

just says "sisesta 0 rida ja 5 veerg" (in english enter the 0 row and 5 column" endlessly no matter how many times i enter numbers

numbers are kinda off too... 0 and 5? where does that come form where did i go wrong with that

the first one does perfectly enter element 0
enter elemnt 1
enter elemet 2
etc...

now u can understand where second starts, i hope

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



int main (void)



{

int maatriks[5] [5];
int esimene[5];
int i,j,l;



for (i=0;i<5;i++)
{
printf ("sisesta %d arv esimese mssiivi jaoks ", i);
scanf ("%d", &esimene[i]);
}

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



*start of second matrix (maatriks = matrix)*

for (i=0;i<5;j++)
{
    for(l=0; l=5; l++)
    {
             printf ("sisesta %d rida ja %d veerg ", i, l);
             scanf ("%d", &maatriks[i][l]);
             
    }
}   

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

     printf("\n");
     
     
     
     









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



Was This Post Helpful? 0
  • +
  • -

#30 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:35 PM

No.. I don't. Is that a variable name, or some part of your code? Do you mean to say 'second for-loop' instead of 'matrix'?
Was This Post Helpful? 0
  • +
  • -

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