...

View Full Version : Arrays



johnr100
07-05-2006, 10:46 AM
HI,

sorry this is such a basic question -

I have an array of 10 numbers, i need to print the first number and then add the second number and print the total, i then need add the 3rd number and print the total - etc until the end of the ten numbers -

eg 1 1
2 3
3 6
4 10etc

thanks for any ideas -
Johnr

coothead
07-05-2006, 12:02 PM
Hi there johnr100,

and a warm welcome to these forums. ;)

does this help...

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
<!--
#numbers {
width:100px;
font-family:monospace;
border:1px solid #000;
padding:10px;
margin:30px;
}
-->
</style>

<script type="text/javascript">
<!--
var nums=new Array(1,2,3,4,5,6,7,8,9,10);
var temp=0;
window.onload=function() {
for(c=0;c<nums.length;c++) {
temp=temp+nums[c];
if(nums[c]<10) {
nums[c]='0'+nums[c];
}
document.getElementById('numbers').innerHTML+=nums[c]+'. '+temp+'<br />';
}
}
//-->
</script>

</head>
<body>

<div id="numbers"></div>

</body>
</html>
coothead

Philip M
07-05-2006, 06:50 PM
I am sure that johnr100's teacher will be most impressed at the spped at which he has leaned such sophistication! But sadly if he simply copies other peoples' work he will never learn, and in future every time he gets the answer right the teacher will suspect that he has cheated. In the long run it is unhelpful and counter-productive to do students' homework for them.

coothead
07-05-2006, 07:10 PM
Hi there Philip,

you will probably tell me that I am obtuse but how do you differentiate between students and non students. :confused:
I can only see people with problems. ;)

coothead

felgall
07-05-2006, 09:42 PM
"If you fish for a man you feed him for a day. If you teach him to fish you feed him for life." (I can't remember who said that but it is very relevant).

If you teach people how to write the code themselves instead of writing it for them then it doesn't matter whether the person is a student or not.

coothead
07-05-2006, 10:05 PM
Hi there felgall,

alternatively...

'He who can, does. He who cannot teaches'

George Bernard Shaw

I am only here to try and solve problems. If this is right or wrong, it is not for me to say.
I will leave that to those with the problems. :D

coothead

Philip M
07-06-2006, 09:58 AM
“Give a man a fish; you have fed him for today. Teach a man to fish; and you will not have to listen to his incessant whining about how hungry he is.”—Author unknown

“Give a man a fish; you have fed him for today. Teach a man to fish; and you can sell him fishing equipment.”—Author unknown

“Give a man a fish; you have fed him for today. Teach a man to use the Internet and he won't bother you for weeks.”—Author unknown

“Teach a man to fish and you feed him for a lifetime. Unless he doesn't like sushi—then you also have to teach him to cook.”—Auren Hoffman, Herald Philosopher

“Give a man a fish; you have fed him for today. Teach a man to fish, and he will sit in the boat and drink beer all day.”—OldFox

“Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime. Teach a man to sell fish and he eats steak.”—Author unknown

Coothead - I see you are in Chertsey, which is not a thousand miles away from me.

coothead
07-06-2006, 10:21 AM
Hi there Philip,

... I see you are in Chertsey, which is not a thousand miles away from me.
Oh my gosh, I hope that does not mean that, I will be getting the 'middle of the night bang on the door'. :eek:

coothead



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum