Flim_Flam Posted October 22, 2007 Share Posted October 22, 2007 I'm in a programming logic and design class. I had to work late last Tuesday and missed class and wasn't able to get ahold of anyone for class notes. I have an assigmnet due that states : "Use a For/Next Loop to calculate the average of 5 numbers" The chapeter we covered is on Arrays, so I'm assuming I'll need to use an array of some sort. All of our programs we write are just in Basic/Pseudocode. If anyone could help me out I'd appreciate it. I've been staring at the book for 2 hours and have not gotten anywhere. Link to comment Share on other sites More sharing options...
Jim825 Posted October 23, 2007 Share Posted October 23, 2007 My BASIC is a bit rusty, so here's some pseudo-code. It shouldn't take much to convert it to BASIC: First, fill a 5 entry array with your values. Now, here's the pseudo-code to calculate the average: Total = 0 FOR Count = 1 to 5 Total = Total + Array[Count] Average = Total / Count NEXT Count PRINT Average How's that? Alternatively, if you only want to calculate the average once, you could simply move the "Average = Total / Count" statement outside the FOR loop and simply use the statement "Average = Total / 5" Total = 0 FOR Count = 1 to 5 Total = Total + Array[Count] NEXT Count Average = Total / 5 PRINT Average Link to comment Share on other sites More sharing options...
krawhitham Posted October 23, 2007 Share Posted October 23, 2007 Dim $Number $Total = 0 $Number[1]=10 $Number[2]=20 $Number[3]=30 $Number[4]=40 $Number[5]=50 For $X= 1 to 5 Step 1 $Total = $Total + $Number[X] $Average = $Total / $X Next PRINT $Average Link to comment Share on other sites More sharing options...
Yankee4Life Posted October 23, 2007 Share Posted October 23, 2007 Dim $Number $Total = 0 $Number[1]=10 $Number[2]=20 $Number[3]=30 $Number[4]=40 $Number[5]=50 For $X= 1 to 5 Step 1 $Total = $Total + $Number[X] $Average = $Total / $X Next PRINT $Average Oh yeah? Same to you. Link to comment Share on other sites More sharing options...
Homer Posted October 23, 2007 Share Posted October 23, 2007 you guys never seem to amaze me...sorry, cease, cease to amaze me. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.