Jogo de Matematica

Jogo para exercitar operações básicas da matemática.
Game to exercise the basics math operations

print("press----> (1)Easy, (2)medium, (3)hard, (4)very hard?")
level = io.read("*n")
print("\n\n\n")

    if level == 1 then
        v = 10
        x = 10
    elseif level == 2 then
        v = 20
        x = 15
    elseif level == 3 then
        v = 30
        x = 20
    elseif level == 4 then
        v = 50
        x = 25
    end
i = 1
errors1 = 0
    while i < v do
        a = math.random (x)
        b = math.random (x)
        print(a.." + "..b.." = ")
        resultgamer = io.read("*n")
        result = a + b
        if resultgamer == result then
            print("ok\n")
            i = i + 1
        else
            print("error\n")
            i = i + 1
            errors1 = errors1 + 1
        end
    end
print("                                      ")
print("#######################################")
print(errors1.." erros in "..v.." operations")
print("#######################################")
print("                                      ")

errors2 = 0
i = 1
    while i < v do
        a = math.random (x)
        b = math.random (x)
        print(a.." - "..b.." = ")
        resultgamer = io.read("*n")
        result = a - b
        if resultgamer == result then
            print("ok\n")
            i = i + 1
        else
            print("error\n")
            i = i + 1
            errors2 = errors2 + 1
        end
    end
print("                                      ")
print("#######################################")
print(errors2.." erros in "..v.." operations")
print("#######################################")
print("                                         ")

errors3 = 0
i = 1
    while i < v do
        a = math.random (x)
        b = math.random (x)
        c = math.random (2)
        if c == 2 then
            print(a.." + "..b.." = ")
            resultgamer = io.read("*n")
            result = a + b
            if resultgamer == result then
                print("ok\n")
                i = i + 1
            else
                print("error\n")
                i = i + 1
                error3 = error3 + 1
            end
        else
            print(a.." - "..b.." = ")
            resultgamer = io.read("*n")
            result = a - b
            if resultgamer == result then
                print("ok\n")
                i = i + 1
            else
                print("error\n")
                i = i + 1
                errors3 = errors3 + 1
            end
        end
    end
print("                                      ")
print("#######################################")
print(errors3.." erros in "..v.." operations")
print("#######################################")
print("                                         ")

errors4 = 0
i = 1
    while i < v do
        a = math.random (x)
        b = math.random (x)
        print(a.." X "..b.." = ")
        resultgamer = io.read("*n")
        result = a*b
        if resultgamer == result then
            print("ok\n")
            i = i + 1
        else
            print("error\n")
            i = i + 1
            errors4 = errors4 + 1
        end
    end
print("                                      ")
print("#######################################")
print(errors4.." erros in "..v.." operations")
print("#######################################")
print("                                         ")

errors5 = 0
i = 1
    while i < v do
        a = math.random (x)
        b = math.random (x)
        print(a.." / "..b.." = ")
        resultgamer = io.read("*n")
        result = a/b
        if resultgamer == result then
            print("ok\n")
            i = i + 1
        else
            print("error\n")
            i = i + 1
            errors5 = errors5 + 1
        end
    end
print("                                      ")
print("#######################################")
print(errors5.." erros in "..v.." operations")
print("#######################################")
print("                                         ")

errors6 = 0
i = 1
    while i < v do
        a = math.random (x)
        b = math.random (x)
        c = math.random (4)
        if c == 1 then
            print(a.." + "..b.." = ")
            resultgamer = io.read("*n")
            result = a + b
            if resultgamer == result then
                print("ok\n")
                i = i + 1
            else
                print("error\n")
                i = i + 1
                errors6 = errors6 + 1
            end
        elseif c == 2 then
            print(a.." - "..b.." = ")
            resultgamer = io.read("*n")
            result = a - b
            if resultgamer == result then
                print("ok\n")
                i = i + 1
            else
                print("error\n")
                i = i + 1
                errors6 = errors6 + 1
            end
        elseif c == 3 then
            print(a.." X "..b.." = ")
            resultgamer = io.read("*n")
            result = a*b
            if resultgamer == result then
                print("ok\n")
                i = i + 1
            else
                print("error\n")
                i = i + 1
                errors6 = errors6 + 1
            end
        elseif c == 4 then
            print(a.." / "..b.." = ")
            resultgamer = io.read("*n")
            result = a/b
            if resultgamer == result then
                print("ok\n")
                i = i + 1
            else
                print("error\n")
                i = i + 1
                errors6 = errors6 + 1
            end
        end
    end
print("                                      ")
print("#######################################")
print(errors1.." erros in "..v.." operations")
print("#######################################")
print("                                       ")
print("                                       ")
print("                                       ")
print("                                       ")
print("                                       ")
print("                                       ")
totalerrors = errors1 + errors2 + errors3 + errors4 + errors5 + errors6
print("#############################################")
print(totalerrors.." erros in "..(v*6).." operations")
print("#############################################")

voltar(back)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.