urgent help
-
But did you read my reply? I need to know your requiremts, i.e. what should your code do? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
But did you read my reply? I need to know your requiremts, i.e. what should your code do? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]double d[150]; double c[150][3],d[150] is a minimum value of c[150][3], so i want to accumulate how many numbers in column 1,2 and 3 respectively, and sum each column value. that is all..thanks a lot. for (int k = 0; k< 150; k++) { if (d[k] == c[k][0]) { sum1 = c[k][0]; sum1 = sum1 + 1; num1 = num1 + 1; } if (d[k] == c[k][1]) { sum2 = c[k][1]; sum2 = sum2 + 1; num2 = num2 + 1; } if (d[k] == c[k][2]) { sum3 = c[k][2]; sum3 = sum3 + 1; num3 = num3 + 1; }
Li Zhiyuan 5/10/2006
-
double d[150]; double c[150][3],d[150] is a minimum value of c[150][3], so i want to accumulate how many numbers in column 1,2 and 3 respectively, and sum each column value. that is all..thanks a lot. for (int k = 0; k< 150; k++) { if (d[k] == c[k][0]) { sum1 = c[k][0]; sum1 = sum1 + 1; num1 = num1 + 1; } if (d[k] == c[k][1]) { sum2 = c[k][1]; sum2 = sum2 + 1; num2 = num2 + 1; } if (d[k] == c[k][2]) { sum3 = c[k][2]; sum3 = sum3 + 1; num3 = num3 + 1; }
Li Zhiyuan 5/10/2006
something like the following?
int n;
int sum[3];
int num[3];
for (n=0; n<3; n++)
{
sum[n]=0;
num[n]=0;
}
for (int k = 0; k< 150; k++)
{
for (n=0; n<3; n++)
{
if (d[k] == c[k][n])
{
sum[n] = sum[n] + d[k]; // or sum[n] += d[k]
num[n] = num[n] + 1; // see the above remark
}
}
}:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
dear all how to solve the following problem..thanks a lot.. for (int k = 0; k< 150; k++) { if (d[k] == c[k][0]) { sum1 = c[k][0]; sum1 = sum1 + 1; num1 = num1 + 1; } why sum1 can't accumulate..it always showed me 1 + the previous value...
Li Zhiyuan 5/10/2006
sum1 doesn't accumulate as you are assigning a fresh value to it:
li zhiyuan wrote:
sum1 = c[k][0];
before you accumulate
li zhiyuan wrote:
sum1 = sum1 + 1;
Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
-
dear all how to solve the following problem..thanks a lot.. for (int k = 0; k< 150; k++) { if (d[k] == c[k][0]) { sum1 = c[k][0]; sum1 = sum1 + 1; num1 = num1 + 1; } why sum1 can't accumulate..it always showed me 1 + the previous value...
Li Zhiyuan 5/10/2006
li zhiyuan wrote:
it always showed me 1 + the previous value...
Because that's exactly what you've coded it to do. Computers do what they're told, no more, no less, which may not always be what you want.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
li zhiyuan wrote:
it always showed me 1 + the previous value...
Because that's exactly what you've coded it to do. Computers do what they're told, no more, no less, which may not always be what you want.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
DavidCrow wrote:
Computers do what they're told, no more, no less
You are a dreamer, my friend. :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
DavidCrow wrote:
Computers do what they're told, no more, no less
You are a dreamer, my friend. :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]CPallini wrote:
You are a dreamer, my friend.
How so?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
CPallini wrote:
You are a dreamer, my friend.
How so?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Computers do anything but what you've told to do. ;P
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
Computers do anything but what you've told to do. ;P
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]CPallini wrote:
Computers do anything but what you've told to do.
yeah .... i agree.... ! :)
-
Computers do anything but what you've told to do. ;P
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]Hard of hearing; practically deaf in some cases!
-
something like the following?
int n;
int sum[3];
int num[3];
for (n=0; n<3; n++)
{
sum[n]=0;
num[n]=0;
}
for (int k = 0; k< 150; k++)
{
for (n=0; n<3; n++)
{
if (d[k] == c[k][n])
{
sum[n] = sum[n] + d[k]; // or sum[n] += d[k]
num[n] = num[n] + 1; // see the above remark
}
}
}:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]thanks, i tried your suggestion already, but still problem...num[n] is no problem, sum[n] still has problem, when i used sum[n] += d[k], the result is sum[0] = sum[1] = sum[2] = 0; if i used sum[n] = sum[n] + 1; the result is same with num[n], what happened? thanks
Li Zhiyuan 5/10/2006
-
thanks, i tried your suggestion already, but still problem...num[n] is no problem, sum[n] still has problem, when i used sum[n] += d[k], the result is sum[0] = sum[1] = sum[2] = 0; if i used sum[n] = sum[n] + 1; the result is same with num[n], what happened? thanks
Li Zhiyuan 5/10/2006