Hello, I've got a C++ task that I need to do but I wasn't learning C++ before and it's kinda hard for me, so I decided to ask you guys for help. Here's the task: You have a two dimensional massive E[m][n]. m = 4, n = 3. All the negative massive elements need to be changed to the columns that the element is in sum. The answers need to be put in a .txt file.
Would there be a person who could help me with this? The only thing I know how to do is the second part where I need to write the answers in the .txt file.
A bump from time to time would be nice :)

9 years ago

Comment has been collapsed.

Is C++ hard?

View Results
Yes, yes of course
Hell no.
Potato cannon nerf gun

Bump for solved:) Thanks a lot!

9 years ago
Permalink

Comment has been collapsed.

I think you need to learn a 2D array, or a multi-dimensional array. The structure is the same for the others languages, then your time is not wasted ;)

9 years ago
Permalink

Comment has been collapsed.

All the negative massive elements need to be changed to the columns that the element is in sum.

ehrm could you repeat this with other words :O

9 years ago
Permalink

Comment has been collapsed.

Hmm, If an element in the massive is negative, it needs to be change to the sum of the column that it is in. :D that's as best as I can do with the translating of it :D

9 years ago
Permalink

Comment has been collapsed.

basically 2 FOR, one for M and an inner FOR for N

9 years ago
Permalink

Comment has been collapsed.

Manco io ci ho capito una mazza, ma fortunatamente per lui so di cosa ha bisogno ;P

9 years ago
Permalink

Comment has been collapsed.

ho intuito che fosse una matrice, ma non l'ho mai sentita chiamare massive onestamente xD

9 years ago
Permalink

Comment has been collapsed.

... gli scherzi di google traduttore :D

9 years ago
Permalink

Comment has been collapsed.

the entitity of gloomy colossal particles demand transformation directed toward the cavalcada such piece befalls amount

there, I used a thesaurus on every word :D

https://www.youtube.com/watch?v=DW1lxwsK5_Q

9 years ago*
Permalink

Comment has been collapsed.

10/10 I would Greenlight that.

9 years ago
Permalink

Comment has been collapsed.

I ... ummm.

THE ANSWER IS GREEN!

(free bump?)

9 years ago
Permalink

Comment has been collapsed.

ummm who gave you this C++ task?

9 years ago
Permalink

Comment has been collapsed.

It was Lord GabeN himself

9 years ago
Permalink

Comment has been collapsed.

Lord GabeN could have done that faster than asking the question upon you thou ;)

9 years ago
Permalink

Comment has been collapsed.

Could he though, could he?

9 years ago
Permalink

Comment has been collapsed.

for (i = 0; i < 4; i++) { for (j = 0; j < 3; j++) { if (arr[i][j] < 0) { arr[i][j] = (i+1) + (j+1); } } }

I give up on this markup.

9 years ago
Permalink

Comment has been collapsed.

why i+1 and j+1? if it's a sum of column, shouldn't it be i+i?

9 years ago
Permalink

Comment has been collapsed.

Indexes of array start from 0 as I remember, so column 1 will have 0 index. (haven't seen any C++ code for 2 years)

UPD: +I think EndLau need column and row sum, not colunm and column.

9 years ago*
Permalink

Comment has been collapsed.

ok, if from that point of view. but it's still, sum of column, so should be i+i (+2), why go with j+1 too, than it would be sum of column + row. that might be what he's asking tho, translation might be off as well, who knows

9 years ago
Permalink

Comment has been collapsed.

It says to change all the negative elements to the sum of a column that the element is in.

9 years ago
Permalink

Comment has been collapsed.

Got it, not index (number), but values of column.)

9 years ago
Permalink

Comment has been collapsed.

replace arr[i][j] = (i+1) + (j+1);

with sth like

arr[i][j] = 0; for (n = 0; n < 3; n++) { arr[i][j] += arr[i][n] }

9 years ago
Permalink

Comment has been collapsed.

Not a master of C++ but i think this should work.
Edit 2: nevermind my code, i didn't see it's only column :p

9 years ago*
Permalink

Comment has been collapsed.

not sure, maybe my english s bad or OP chose bad wording, but we don't even know which of this 2D array is the row and which the column.

you're suggesting to sum up all elements of the array, while I'm suggesting that the second array represents the column, and only add up the column, because:

All the negative massive elements need to be changed to the columns that the element is in

but, like I said, I'm not a native english speaker, I don't understand OP's problem very well and the task generally leaves some questions unanswered


oh, and you're only overwriting the same position, not summing it up, but changing

E[i][j] = E[x][y];
to
E[i][j] += E[x][y];
would probably fix it.

again, we don't even know if we're supposed to reset E[i][j] before accessing it again to be a part of the sum or if we should leave it as is to sum it up. if E[i][j] is a huge negative number, we'll just end up with a negative number again. if all values are negative, the numbers will just get smaller and smaller ...

9 years ago*
Permalink

Comment has been collapsed.

lol yeah, me neither (i meant native speaker of course)*. But, your solution should give the basic idea for it
Edit: Oh yeah! lol forgot the plus sign thanks :D

9 years ago*
Permalink

Comment has been collapsed.

Man, trial and error with the debugger is easier than writing it manually xD

9 years ago
Permalink

Comment has been collapsed.

Uhm, aren't you supposed to do your homework by yourself?

9 years ago
Permalink

Comment has been collapsed.

It clearly says that YOU personally have to help me with it. There's even a stamp with a goose next to it

9 years ago
Permalink

Comment has been collapsed.

That's what I'm up to right now:

const int m = 4;
const int n = 3;

int main()
{
ofstream fr("asd.txt");
int E[m][n];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (E[m][n] < 0)
{
E[m][n] = (i + j);
}
}
cout << E[m][n] <<endl;
fr << E[m][n] <<endl;
}
fr.close();
_getch();
}

9 years ago
Permalink

Comment has been collapsed.

you're never assigning values to your array in the first place, so how would you know what originial values you're starting with and what result you're expecting?

9 years ago
Permalink

Comment has been collapsed.

I suggest you change your if code as it's checking the same value over and over again, look at TheDopefish* comment above.. Might help not sure though.
Edit: Oh, and initialize your arrays first, by the way like what TheDopefish said.

9 years ago*
Permalink

Comment has been collapsed.

like this? int E[m][n] = { { 2, 3 }, { -3, 4 }, { 0, 0 }, { 2, -2 } };

9 years ago
Permalink

Comment has been collapsed.

As far as i can remember it yeah

9 years ago
Permalink

Comment has been collapsed.

Sign in through Steam to add a comment.