-
I need very fast help, like within the hour, please!
I need to make a programm (probably childs play to most of u)
But i have no clue how to do it, so please help, i need it done really fast.
The prgoramm is:
Write a programm in C++ that finds a matrixs A[4][7], then the sums (by adding them togeter) of all the positive elements of the numbers in the matrix from the third column and all the columns to the right of it(one sum for each column). And the shows it on the screen.
If anyone could quicky make me the programm i would be very greatfull.
It is a part of my homework that i have to send in with in the hour AT max 2 hours and i have no clue how to do that part. Really need help
Well i think i even got the matix down form this part, but i got no clue how to axess a column, so start multiplying them......
right now form this part this is what i manuaged to make, but.. i can only make it get some random diagonal? i got no idea how to get to a column and sum the numbers up there?
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define RIDU 4
#define VEERGE 7
#define MAX 150
#define MIN 10
int main (void)
{
int maatriks [RIDU] [VEERGE];
int i,j;
srand(time(NULL));
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
maatriks[i][j]=rand()%(MAX-MIN)+MIN;
}
}
printf("Generated maatrx on:\n\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
printf("%4d", maatriks[i][j]);
}
printf("\n\n");
}
printf("third column?\n\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
if (i>=j) printf("%4d", maatriks[i][j]);
}
printf("\n");
}
return 0;
}
-
Re: I need very fast help, like within the hour, please!
The third column corresponds to j = 2
so there is no need to a a for loop with j in your code to print out the 3rd column.
-
Re: I need very fast help, like within the hour, please!
still dont understand how do i write a code that for example will that the third colum and sum up all the numbers there? Very greatfull for any help, i need to despretly get it done.
-
Re: I need very fast help, like within the hour, please!
With that i manuaged to get the last column of my matrix on the screen... (no clue how to generate anything in the middle on the screen alone), but how on earth can i get the programm to sum up all the numbers from that column now?
printf("Last column\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
if (j>5) printf("%4d", maatriks[i][j]);
}
printf("\n");
}
-
Re: I need very fast help, like within the hour, please!
Please use the code tags when posting code so that it is easier to read and understand. Also you have posted to the wrong forum. This forum is regarding visual c++ programming where as your question relates to just c++ - which is for the 'c++ (non visual c++) forum'.
Also as your question relates directly to homework, I would suggest that you read the FAQ
http://forums.codeguru.com/showthrea...ork-assignment
I doubt that any member will write the code for you. I did for one query before and was politely rebuked by other members!
If you write the code yourself and then have a specific question about what you have written then you will probably receive help.
To quote from the above FAQ
Quote:
The very purpose of your homework is to verify that you have understood a subject and are able to apply the learned knowledge to solving specific problems. By having someone else do the assignment for you, you are not only cheating at your teachers, but also at yourself, since you pretend (and perhaps even believe) to have acquainted knowledge and skills that you actually don't have.
-
Re: I need very fast help, like within the hour, please!
i am not asking your to write my entire code i am asking for help how to get over obsicales, and this whole thing i asked is just a tiny bit of it, i dont have any clue how i can add up the column numbers.
And sry about the wrong place, i dont really know whats visual or none visual c++ coding.
Also i dunno where your from, but where i live it is perfectly fine to get your code done using internet and finding or getting help from anywhere. We can even do it on our programming exam.
Also, this is right now the last day i can do it, and i am NOT doing it at home, it is like an extra assigmnet to my homework, to get it done, i am in my class and my teacher is almost literally next to me, what our teacher says to that is basically " it dosnt matter if you KNOW how to do it right that second, what matters is that u can find out how from anywhere you like, and u will learn how to do it from that,
-
Re: I need very fast help, like within the hour, please!
Quote:
Originally Posted by
SwiftXShadow
i am not asking your to write my entire code i am asking for help how to get over obsicales, and this whole thing i asked is just a tiny bit of it, i dont have any clue how i can add up the column numbers.
And sry about the wrong place, i dont really know whats visual or none visual c++ coding.
Also i dunno where your from, but where i live it is perfectly fine to get your code done using internet and finding or getting help from anywhere. We can even do it on our programming exam.
The policy of this forum is not to write homework code for people. You don't learn anything by having somebody do your work for you, and where most of us are from, it would be regarded as cheating and dishonest.
To add all numbers in a column, you need a loop and a counter.
Initialize the counter to 0;
Write a loop incrementing from 0 through the number of rows - 1.
Use the incrementing variable for the to access the row of the matrix, and keep the column number constant.
Inside the loop, add the value found at the row and column of your matrix to your counter.
-
Re: I need very fast help, like within the hour, please!
Basically, you ignored what I said. To get a particular column, you do not need
to loop on j.
j = 0 ... gives the first column
j = 1 ... gives the second column
etc.
Code:
j = 2;
for(i=0; i<RIDU; i++)
{
printf("%4d", maatriks[i][j]);
}
printf("\n");
-
Re: I need very fast help, like within the hour, please!
not ignored, just coulnt understand....
-
Re: I need very fast help, like within the hour, please!
Quote:
Originally Posted by
SwiftXShadow
not ignored, just coulnt understand....
Replace j with a number. If you want the third column, maatriks[i][2]
-
Re: I need very fast help, like within the hour, please!
wow that was soo simple, cant imagine how basic my questions must look to you..... i was experimenting with massive ammounts of code to try to generate it somehow.
But how can i make 1 colum sum up all its numbers?
-
Re: I need very fast help, like within the hour, please!
I already explained that.
-
Re: I need very fast help, like within the hour, please!
ouuuu
u mena this part
j = 2;
for(i=0; i<RIDU; i++)
{
printf("%4d", maatriks[i][j]);
}
printf("\n");
-
Re: I need very fast help, like within the hour, please!
Quote:
Originally Posted by
SwiftXShadow
ouuuu
u mena this part
j = 2;
for(i=0; i<RIDU; i++)
{
printf("%4d", maatriks[i][j]);
}
printf("\n");
http://forums.codeguru.com/showthrea...99#post2100899
-
Re: I need very fast help, like within the hour, please!
Ummm i must be rly dumb and still dun get it, or i can put a sentance together to propelly tell you my question, hope u dont get too anoyed, you are a big big help.
That piece of code gives me all the numbers in the colum like 54 234 21 52 in a line, which is good... but how do i sum them up. Like 54+234+21+52=361.
Really sincere apologizes if i look like i am mocking your with stupid questions, but i really dont understand, and u have been a very very big help so far already.
-
Re: I need very fast help, like within the hour, please!
Before the loop.
int nTotal = 0;
Inside the loop
nTotal += maatriks[i][2]);
-
Re: I need very fast help, like within the hour, please!
question what exactly does "n total" mean and do? never heard of anything like that before
EDIT, i tryed to add what u said in... but for some reason now when i activate the program, everything broke down int o massive ENDLESS ammount of numbers? so i dont know what to do agian :(
well alteast i THINK i did it as u said....
-
Re: I need very fast help, like within the hour, please!
Quote:
Originally Posted by
SwiftXShadow
question what exactly does "n total" mean and do? never heard of anything like that before
There's no space between n and total.
-
Re: I need very fast help, like within the hour, please!
question what exactly does "n total" mean and do? never heard of anything like that before :( i think i am doing something wrong
i put the int nTotal = 0; to the top where i declare all my other stuff like int i,j;
and then nTotal += maatriks[i][3]); inside one of the loops? wow i just relized it is probably hard for you to understand half of my code because a lot of the words are written in first language
-
Re: I need very fast help, like within the hour, please!
Which part of there is no space between n and total was unclear?
-
Re: I need very fast help, like within the hour, please!
ou sorry, the first sentance of my second post somehow came along with my last one,
i corrected the space but i still coulnt get it work, i think i am putting the nTotal += maatriks[i][3]); in the wrong place maybe? Where exactly in the code am i suppose to put it, the endless numbers stoped with the N fixing, but now simply nothing happens when i add that part? i must be doing something really wrong.
-
Re: I need very fast help, like within the hour, please!
Quote:
Originally Posted by
SwiftXShadow
ou sorry, the first sentance of my second post somehow came along with my last one,
i corrected the space but i still coulnt get it work, i think i am putting the nTotal += maatriks[i][3]); in the wrong place maybe? Where exactly in the code am i suppose to put it, the endless numbers stoped with the N fixing, but now simply nothing happens when i add that part? i must be doing something really wrong.
Let's see what you have. If your instructor is right there, can you ask him/her?
-
Re: I need very fast help, like within the hour, please!
i think i put it in the loop.....(if i understand correctly what loop means..... it is an english word that i have never heard before, my programming is taught to me in my own language so i am trying really hard to get to the right place)
-
Re: I need very fast help, like within the hour, please!
Quote:
Originally Posted by
SwiftXShadow
i think i put it in the loop.....(if i understand correctly what loop means..... it is an english word that i have never heard before, my programming is taught to me in my own language so i am trying really hard to get to the right place)
Let's see your code.
-
Re: I need very fast help, like within the hour, please!
lol i wish, i can ask but they wont answer, as i said "i have to do it myself by any way i can find out how or feagure out how, he simply wont tell me how, so he isnt an option to find out form"
also a LOT of the code is right now overlaping itself cuz i leave in every single thing i learned right now and once i get something done i delete out the crap. If anything is ununderstandebe because estonian i can translate most
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define RIDU 4
#define VEERGE 7
#define MAX 150
#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");
printf("neljas tulp ja selle arvude summad\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
(nTotal += maatriks[i][3]);
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("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][6]);
}
printf("\n");
}
printf("----------------------------------------\n");
printf("\n\n\n\n");
printf("Neljas tulp ja selle arvude summad\n");
j = 3;
for(i=0; i<RIDU; i++)
{
printf(" %4d", maatriks[i][j]);
}
printf("\n");
return 0;
}
-
Re: I need very fast help, like within the hour, please!
i would use that speical box you guys use to put the code in, but i dont know how u guys get it
-
Re: I need very fast help, like within the hour, please!
You've been told several times you don't need a loop that increments the column variable. You've also been told several times that to access the third column, the index should be 2, not 3.
This is what your summing loop should look like.
Code:
for(i=0; i<RIDU; i++)
{
nTotal += maatriks[i][2];
}
-
Re: I need very fast help, like within the hour, please!
I dont need the third colum ( i need 4,5,6,7) i think i transalted that question in the start a bit wrong.
And about the loop i dont really understand what that word means so i mix and matched things...
-
Re: I need very fast help, like within the hour, please!
so how do u get it on scr
-
Re: I need very fast help, like within the hour, please!
Quote:
Originally Posted by
SwiftXShadow
I dont need the third colum ( i need 4,5,6,7) i think i transalted that question in the start a bit wrong.
And about the loop i dont really understand what that word means so i mix and matched things...
Then put the j loop back in, but start it at the first column you want to sum.
-
Re: I need very fast help, like within the hour, please!
what is j loop
this part?
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");
}
i dont get the "loop" word.
Also since it is late here (17:33pm), my teacher told me to go home and finish it there and send it to him by midnight.... i gtg for like 30mins or so to get home and keep doing it there.
-
Re: I need very fast help, like within the hour, please!
-
Re: I need very fast help, like within the hour, please!
soo loop is the thing that makes the programm repeat itself?
-
Re: I need very fast help, like within the hour, please!
SwiftXShadow, you really need to take the time to read that tutorial. I know you are feeling pressured right now, but if you can't grasp the concept of loops, then future assignments will just be that much harder. You should figure out how to sum all the numbers in a regular array. And then, once you have that down (using loops), you should read up on multidimensional arrays.
-
Re: I need very fast help, like within the hour, please!
Quote:
Originally Posted by
Alterah
SwiftXShadow, you really need to take the time to read that tutorial. I know you are feeling pressured right now, but if you can't grasp the concept of loops, then future assignments will just be that much harder. You should figure out how to sum all the numbers in a regular array. And then, once you have that down (using loops), you should read up on multidimensional arrays.
If i cant finish this code, then i will fail the class (there are no retests or anything, this class dosnt end with an exam but the assigments we are given at the end, which they call tests, are with about the same value, some of the stuff like how to add up the colums we have never talked about in any of our classes, they expect us to find information anyway possible to finish the so called test, or as i like to call it homework since we aren't obligated to do it in class), and then i wont have anymore assingments. Right now i am literally just trying to get it done any way possible.
-
Re: I need very fast help, like within the hour, please!
To format your code in the special code box, you need to 'go advanced' in posting a message - and not just use quick reply.
Then select your code and click on the '#' in the formatting options that appear. If you then use Preview Post you should see your code formatted in the proper code box.
Code:
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");
}
It also helps if you format your code with indentations for block levels like this
Code:
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");
}
This helps yourself and anyone else trying to understand the code.
-
Re: I need very fast help, like within the hour, please!
Quote:
Originally Posted by
SwiftXShadow
If i cant finish this code, then i will fail the class (there are no retests or anything, this class dosnt end with an exam but the assigments we are given at the end, which they call tests, are with about the same value, some of the stuff like how to add up the colums we have never talked about in any of our classes, they expect us to find information anyway possible to finish the so called test, or as i like to call it homework since we aren't obligated to do it in class), and then i wont have anymore assingments. Right now i am literally just trying to get it done any way possible.
Then what will you do next time? You need to understand the fundamental concepts. Most of us write code that hasn't been written before, or code you can't just find a solution to on the net. You need to understand what the tools are, how they work, what they can do for you and how you can apply them. That's what your instructor is testing you on. Trying to pass a class without doing the requisite homework, then coming to a bulletin board and expecting your work to be done for you in and hour or two is an unrealistic expectation.
-
Re: I need very fast help, like within the hour, please!
If I understand the problem correctly, you have one matrix, A[4][7]. So, it's 4 rows and 7 columns. You need to then add the numbers starting at the third column going through the 7th column for each column correct?
Consider a similar problem. You have to add all the numbers in column 3 and 4 together. For this problem, it's probably easier to do this a row at a time. You start with the first row. Grab the numbers starting at the third column and go to the last column. Then, you bump your row index up to the second row, etc. Consider the following matrix:
Code:
1 2 3 4
5 6 7 9
3 2 5 6
That is a 3 X 4 matrix, lets call it Matrix.
If I wanted to get the sum of all the numbers in the last two columns I would first initialize some counter to zero. I would start at the 3rd element in the above array from the first row, or Matrix[0][2]. I would add this onto the counter, then move onto the next element in the row, or Matrix[0][3]. At this point, I've run out of numbers in the row, so I need to jump down to the second row and start over, or to Matrix[1][2].
But this isn't quite what your assignment is asking you to do. It looks like it wants you to add all the positive numbers from columns 3,4,5,6, and 7. So, instead of moving to the right in the above example, you need to move down, so you'll need to access Matrix[0][2], Matrix[1][2], and so forth. Once you get to the forth row Matrix[3][2], you'll now have your sum for that column. There's an additional requirement that the numbers you sum be positive, but that shouldn't be too difficult.
The code for this assignment is not very difficult, and if you find yourself writing a bunch of code, you are probably doing something wrong.
-
Re: I need very fast help, like within the hour, please!
If i pass it then atleast i can keep trying to learn, i woulnt be on these forums if i didnt care if i failed or passed.
And so far all the codes we had to write have been basically by the book, stuff we can look off our lectors examples and finish them.
This time i just dont know how to do it, but i dont want to fail the class, and flunk out.
-
Re: I need very fast help, like within the hour, please!
so is it suppose to look like something like that to get the sum for the fourth column?
Code:
int nTotal = 0;
{
}
printf("Fourth column and its sum\n");
for(i=0; i<RIDU; i++)
{
for(j=0; j<VEERGE; j++)
{
if (j<1) printf("%4d", maatriks[i][3]);
nTotal += maatriks[i][3]);
}
printf("\n");
}
though aside from the fact i dont know how to make it on the screen it feels like it is still missing a few lines of code...
-
Re: I need very fast help, like within the hour, please!
You're guessing without understanding. You can't code that way. I know you're under a deadline, but you don't seem to understand why you're doing what you're doing. You either want a j loop, or you want the second index hardwired, but not both, depending on whether you want to sum one column or multiple.
-
Re: I need very fast help, like within the hour, please!
I looked that https://www.youtube.com/watch?v=gZVg3pNOAtc short tutorial video video through about 3-4 times.... and and i noticed some similartys of what u were telling to me to what he is doing.
EDIT: and what i want to do is sum up EACH of the columns sepretly?!
-
Re: I need very fast help, like within the hour, please!
SwiftXShadow, there isn't much more we can do without giving you the answer. GCDEF has given plenty of hints.
-
Re: I need very fast help, like within the hour, please!
Quote:
Originally Posted by
SwiftXShadow
EDIT: and what i want to do is sum up EACH of the columns sepretly?!
Is that a statement or a question? That seems to be your third different requirement now.
-
Re: I need very fast help, like within the hour, please!
i guess i failed explaning myself in english again.
What i want to do is, sum each of the colums like
Fourth colum 5+2+1+5=13
fifth column 20+1+3+2=26
sixth colum 12+8+5+12=37
seventh column 2+4+6+8=20
but it dosnt really matter that much anymore, i gotta send it in 28 minutes, so no way i will be able to feagure it out now, when i havent been able to for hours and hours.
-
Re: I need very fast help, like within the hour, please!
That makes it a little more complicated. You'll want an array for your total counters then too. I'd suggest you read the chapters in your book covering arrays and for loops until they make sense. Keep in mind in your examples, index i accesses the row and index j access the columns. j should only loop over the columns you're interested in. Therefore it won't start at 0.
-
Re: I need very fast help, like within the hour, please!
lol my book..... i wish i had one, we never had a book for this. Everything we learned is from class and examples given, never seen a book or heard one mentioned.
if i had a book I woulnt have to ask someone how to do it or try to search the internet for random places in english that i bearly can read cuz i dont understand half the c++ lanugae words used.
-
Re: I need very fast help, like within the hour, please!
If you were going to print out the numbers in the array, column by column, how would you do that?
-
Re: I need very fast help, like within the hour, please!
this is how i get the numbers printed out column by column?
Code:
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");
-
Re: I need very fast help, like within the hour, please!
That is way too much code to do that. You should only need 2 for loops. One to iterate through a column, and then the other to move you to the next column.