Skip to content

Commit

Permalink
math easier
Browse files Browse the repository at this point in the history
  • Loading branch information
EricZhou committed Apr 12, 2021
1 parent 5dfa8d3 commit 21c366b
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions driver_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (d *DriverMath) GenerateIdQuestionAnswer() (id, question, answer string) {
var mathResult int32
switch operators[rand.Int31n(3)] {
case "+":
a := rand.Int31n(100)
b := rand.Int31n(100)
a := rand.Int31n(20)
b := rand.Int31n(20)
question = fmt.Sprintf("%d+%d=?", a, b)
mathResult = a + b
case "x":
Expand All @@ -74,15 +74,12 @@ func (d *DriverMath) GenerateIdQuestionAnswer() (id, question, answer string) {
question = fmt.Sprintf("%dx%d=?", a, b)
mathResult = a * b
default:
a := rand.Int31n(100)
b := rand.Int31n(100)
if a > b {
question = fmt.Sprintf("%d-%d=?", a, b)
mathResult = a - b
} else {
question = fmt.Sprintf("%d-%d=?", b, a)
mathResult = b - a
}
a := rand.Int31n(80) + rand.Int31n(20)
b := rand.Int31n(80)

question = fmt.Sprintf("%d-%d=?", a, b)
mathResult = a - b

}
answer = fmt.Sprintf("%d", mathResult)
return
Expand Down

0 comments on commit 21c366b

Please sign in to comment.