Hi,

Sticky CAPSLOCK?

>    Can someone please tell me why the below code does not work correctly?
> Here is the problem:  Once I run the program and type in a couple of wrong
> answers and then type in the correct answer I still get the wrong response
> (e.g "No that is wrong! Try again.") But if I type in the correct answer
> first I get the correct response.

Hmmm...

>    I also should add that if I don't use "use strict" and rename my variable
> without "my". The code then works as it should.

use strict isn't buggy, and doesn't do anything more than tell you bad things
about your code.  Hence by elimination the reason must be the "my", now lets
see the code:

> #!/usr/bin/perl -w
> 
> use strict;
> 
>         print ("What is 7 times 7? \n");
> 
> chop (my $input_answer = <STDIN>);

Err... what's this doing here?

> my $answer = 49;
> 
> until($input_answer == $answer) {
>        print ("No that is wrong! Try again. \n");
>        chop(my $input_answer = <STDIN>);
> }      print("You got it!!\n");

Change the loop:

while (1) {
    chop(my $input = <STDIN>);
    last if $input = $answer;
    print "No that is wrong!  Try again.\n";
}
print "You got it!!\n";

Jonathan Paton

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to