The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
I'm trying to make a program for a class, or rather help someone make a program for a class. We need to take series of numbers from a text file separated by zeros and calculate the average of each series, along with an average of all the averages
It's a database class and I don't know hardly anything about VB so I'm flummoxed and cannot find the answer online
Loadtextfile (numbers.txt)
Do while not end of file
if zero
OutputAverageText = (accumulator1/counter1)
set accumulator1 to zero
set counter1 to zero
else
count
accumulate
endloop
Loadtextfile (averageoutput.txt)
Do while not end of file
Run accumulator2
Run counter2
endloop
Averageaverageoutput to text = (accumulator2/counter2)
Keep in mind I really don't have the foggiest idea about how to actually do this
First, go to your kitchen, and find two forks. Stick one in your left eye, and the other in your right eye. Now you're ready to begin.
I'd go with pseudo code more like this:
# this array will hold the averages of each line
Array allAverages
foreach line in file
Array numbers = Split(line, "0")
Integer average = Average(numbers)
Print(average)
AddToArray(allAverages, average)
end foreach
Print(Average(allAverages))
The Split() function is documented here. I'm sure VB has some kind of Print() function that you can use in place of what I call "Print". The Average() and AddToArray() functions probably don't exist, but you can google around and see how others have done these.
I'm curious why a database class would make you program in VB instead of you know, T-SQL or something with tables.
The above mentioned pseudo code will work effectively; if you're using VB.NET, and not just VB, there are helper methods (extension methods in this case) that can greatly simplify your life (code provided in C#, but you can get the drift)
// Splits a string on the specific character into an array and removes elements that are string.Empty
myString.Split(new char[] { '0' }, StringSplitOptions.RemoveEmptyEntries)
// Requires using System.Linq;
myArray.Average();
Posts
Accumulator2 Declaration
Counter1 Declaration
Counter2 Declaration
Loadtextfile (numbers.txt)
Do while not end of file
if zero
OutputAverageText = (accumulator1/counter1)
set accumulator1 to zero
set counter1 to zero
else
count
accumulate
endloop
Loadtextfile (averageoutput.txt)
Do while not end of file
Run accumulator2
Run counter2
endloop
Averageaverageoutput to text = (accumulator2/counter2)
Keep in mind I really don't have the foggiest idea about how to actually do this
That code looks pretty unfamiliar though, looks like they may have changed some of the syntax since then.
I'd go with pseudo code more like this:
The Split() function is documented here. I'm sure VB has some kind of Print() function that you can use in place of what I call "Print". The Average() and AddToArray() functions probably don't exist, but you can google around and see how others have done these.
http://www.google.com/search?q=visual+basic+arrays
http://www.google.com/search?q=visual+basic+average+of+an+array
This looks right: haven't tried it, but its your HW.
http://www.fryan0911.com/2009/05/vbnet-how-to-read-csv-file-into-array.html
replace
strline = strlines(0).Split(",") with strline = strlines(0).Split("0") , and you should have it.
once you have it into an array, loops and arithmetic to get your averages.(make sure its average of averages vs average of all the numbers).
Also who the fuck separates numbers with a number?
Blizzard: Pailryder#1101
GoG: https://www.gog.com/u/pailryder
This: 10010010101010101010101100001010
Could be:
10 010 0101 0101 01 010101 011000 01 010
So 10,10,101,101,1,10101,11000,1,10
or
10 010 01 01 01 01 0101 0101 011000 01010
So 10,10,1,1,1,1,101,101,11000,1010
Two completely different sets of numbers. Which would make it impossible.
PSN: SirGrinchX
Oculus Rift: Sir_Grinch
The above mentioned pseudo code will work effectively; if you're using VB.NET, and not just VB, there are helper methods (extension methods in this case) that can greatly simplify your life (code provided in C#, but you can get the drift)
If the class is using mostly Access to teach database concepts and such then VB is very likely as it's built-in. My first database class did this.