If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Please help me with my arrays...!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-10-09, 01:54
andrewmoquin andrewmoquin is offline
Registered User
 
Join Date: Aug 2009
Location: Buffalo, New York
Posts: 2
Please help me with my arrays...!

I have an assignment due on Tuesday and I'm having a few problems with arrays. First I can't seem to get my array to display vertically, it just comes out like 12,34,67,etc. also I'm having difficulty getting the highest and lowest number from the array. My program is supposed to get temperatures from the user and calculate the average, sum, high and low and list all the input. This is what i have so far

[code]

<script language="JavaScript">

var tempInputArray=new Array();


function addToStats() {

var tempInput=document.tempStats.tempInput.value;

tempInputArray.push(tempInput);

var sum=parseFloat(0);

for(i=parseFloat(0); i<tempInputArray.length; i++)
sum+=parseFloat(tempInputArray[i]);

var average=sum/tempInputArray.length;

var max=tempInputArray[0];
for(i=parseInt(1); i<tempInputArray.length; i++)
if(tempInputArray[i]>max {
max=tempInputArray[i];
}


output=(tempInputArray + "<br>");
document.getElementById("output").innerHTML=output

output1=("The # of entries is " + tempInputArray.length + " and the sum is " + sum + "<br>" + "The average is " + average + "<br>" + "The largest is " + max);
document.getElementById("output1").innerHTML=outpu t1
}

function clearForm() {
output="";
document.getElementById("output").innerHTML=output ;

output1="";
document.getElementById("output1").innerHTML=outpu t1;

document.tempStats.tempInput.value="";
}
</script>

[code]

Any help would be greatly appreciated!

Thanks,
-Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On