You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func hello(w http.ResponseWriter,r http.Request) {
s:= statistic{}
sum=0
w.Header().Set("Content-Type", "text/html")
switch r.Method {
case "GET":
/ display the form to the user */
io.WriteString(w, doc1 );
case "POST":
s.arr=r.FormValue("array")
for i:= range s.arr {
if s.arr[i]==0 {
continue
}
integer[i]=int(s.arr[i])
}
cnt=len(integer)
for i := range integer {
sum+=float32(integer[i])
}
s.count=cnt
s.Mean=float32(sum)/float32(cnt)
i=cnt%2
switch(i) {
case 0:
median=float32(integer[cnt/2]+integer[cnt/2-1])/2.0
break
case 1:
median=float32(integer[(cnt+1)/2])/2.0
break
}
s.Median=median
io.WriteString(w, doc2)
}
}
const doc1=`
<title></title>
Statistics
Computes basic statistics for the given list of numbers
`
const doc2=`
<title></title>
Statistics
Computes basic statistics for the given list of numbers
Numbers
{{.arr}}
Count
{{.count}}
Mean
{{.Mean}}
Median
{{.Median}}
`
for some reason once I click calculate on doc1,doc2 does not show up
The text was updated successfully, but these errors were encountered:
package main
import(
"net/http"
"io"
)
type statistic struct{
arr string
count int
Mean float32
Median float32
}
func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":9999", nil)
}
func hello(w http.ResponseWriter,r http.Request) {
s:= statistic{}
sum=0
w.Header().Set("Content-Type", "text/html")
switch r.Method {
case "GET":
/ display the form to the user */
io.WriteString(w, doc1 );
case "POST":
s.arr=r.FormValue("array")
for i:= range s.arr {
if s.arr[i]==0 {
continue
}
integer[i]=int(s.arr[i])
}
cnt=len(integer)
for i := range integer {
sum+=float32(integer[i])
}
s.count=cnt
s.Mean=float32(sum)/float32(cnt)
i=cnt%2
switch(i) {
case 0:
median=float32(integer[cnt/2]+integer[cnt/2-1])/2.0
break
case 1:
median=float32(integer[(cnt+1)/2])/2.0
break
}
s.Median=median
io.WriteString(w, doc2)
}
}
const doc1=`
<title></title>Statistics
Computes basic statistics for the given list of numbers
`const doc2=`
<title></title>Statistics
Computes basic statistics for the given list of numbers
for some reason once I click calculate on doc1,doc2 does not show up
The text was updated successfully, but these errors were encountered: