vb.net - VB - Maths Quiz Check Answer -


i doing project , trying make own maths quiz. basically, have 3 labels , textbox. in first , third label number randomly generated. in second label, mathematical operator selected (either +, - or ÷). in textbox, user input answer equation, brings me question ask:

i can point fine can't head around code check whether answer inputted textbox correct.

i have tried...

 if lbloperator.text = "+" & txtsum.text =num1 +  num2         msgbox("correct")     end if 

but doesnt work.

in end replace msgbox counter count number of correct answers attained on duration of quiz. have tried other things , have been getting error:

conversion string "" type 'double' not valid.

if helps, button put in place randomize operator , number in labels , check if answer correct.

thanks

perhaps help.

given these functions:

    dim dictionary = new dictionary(of string, func(of double, double, double))() _         _         { _             {"+", function(x, y) x + y}, _             {"-", function(x, y) x - y}, _             {"*", function(x, y) x * y}, _             {"/", function(x, y) x / y} _         }      dim process func(of string, string, string, double) = _         function(op, x, y) _             dictionary(op)(double.parse(x), double.parse(y)) 

you can do:

    dim operator = textbox1.text ' "+"     dim num1 = textbox2.text ' "5"     dim num2 = textbox3.text ' "4"     dim result = process(operator, num1, num2) ' 9 

please let me know if helps , how can expand on need go.


Comments