Can anyone create a program that
would test the math skills of the user. Assume that it would test integer addition, The program should ask the question,collect the integer response, evaluate and notify the user if their answer was correct or incorrect. I would assume integers in the range {1..100}.
either shell scripts or perl should be OK
Thanks a bunch
The code you posted has a few syntax errors. Don't use numbered variables ($1, $2 etc) those are reserved by perl for pattern memory and are read-only. Use the warnings pragma:
use warnings;
You have the general idea although you should also validate the user input (like make sure the user has only entered integers) and correct the synax errors. Its also good to add a fall-through condition to the end of an if/elsif chain:
Use rand for what? I thought the user was going to input the numbers and the operation they want to perform ( x + - / etc).
If you want the user to input all the data at one time:
print "Enter two numbers between 1 and 100 and one of the following math operations to perform [ + - x /] and the answer. Example: 3 X 17 = 51. ";
Then you check that there are two numbers, a math operator and the answer.
chomp (my $input = <STDIN>);
my ($int1, $operator, $int2, undef, $answer) = split(/\s+/,$input);
here you validate the input and
perform the math and check the answer