i can get it for the first 2 #’s but i cant get it to keep going.
i put >>>>>> where the code starts and ends that im having trouble with.
Heres the code
//*********
//Connor Weible
//DC225
//Week 2 HW
// ***Create an Array with 100 numbers in it. Each number should be randomly generated, and somewhere between 1 and 100.
// ***Tell me the total of all the numbers in the array.
// ***Tell me the average of all the numbers in the array.
// Tell me the value of the biggest number in the array.
// Tell me the value of the smallest number in the array.
// Sort the array (by hand, DO NOT USE the built in sort() function)
// Tell me the median value of the numbers in the array.
// ***Tell me the mode of the array.
// Put all the steps in its own little function
//*****************
package {
import flash.display.*;
public class Arrayweible extends MovieClip {
public function Arrayweible() {
//declare
var stuff:Array;
//initialize
stuff=new Array(100);
//fill it with stuff
for (var i:int=0; i<stuff.length; i++) {
stuff[i]=Math.floor(Math.random()*100)+1;
}
//trace all the random numbers
for (i=0; i<stuff.length; i++) {
trace("stuff["+i+"] = "+stuff[i]);
}
//random gen code over.
//Sorting the array
//how in the HELL do i do this?!
trace("");
trace("The array is now sorted");
//Sorting code end
//Total of all the numbers in the array
var total:int=0;
for (i=0; i<=stuff.length-1; i++) {
total+=stuff[i];
}
trace("");
trace("Total: "+total);
//total code end
//Average of all numbers
var average:int=0;
for (i=0; i<=stuff.length-1; i++) {
total+=stuff[i];
average=total/100;
}
trace("");
trace("Average: "+average);
//average code end
>>>>>> //Value of the largest number
var largest:int=0;
var champ:int;
var competer:int=0;
for (var i:int=0; i<stuff.length-1; i++) {
for (var j:int = i + 1; j < stuff.length; j++) {
if (stuff[i]>stuff[j]) {
competer=stuff[i];
i++
} else {
competer=stuff[j];
i++
}
largest=champ;
}
}
trace("");
trace("The largest number is: "+largest);
>>>>> //largest code end
//Value of the smallest number
var smallest:int=0;
var loser:int=0;
var compete:int=0;
for (i=0; i<stuff.length-1; i++) {
}
trace("");
trace("The smallest number is: "+smallest);
//smallest code end
//Median of the array
trace("");
trace("The median is: "+stuff[49]);//traces middle!!!
//median code end
//Mode of the array
//vars
var count:int=0;
var prevCount:int=0;
var totalCount:int=0;
//countings, also may need to declare i again once put into functions.
for (var i:int=0; i <stuff.length; i++) {
for (var j:int = i + 1; j < stuff.length; j++) {
if (stuff[i]==stuff[j]) {
count++;
i++;
}
}
//counting vars
if (count>=prevCount) {
totalCount++;
}
prevCount=count;
count=0;
}
trace("");
trace("The mode is: "+totalCount);
//Mode code end
}
}
}

New Topic/Question
Reply


MultiQuote





|