Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
What I don't understand is why the "quit" comparison isn't working. When the user types in "quit", the program states that this is "Too low." Is it being converted to zero? I have it using an "eq" operator, so why doesn't it take the input as a string? Shouldn't the program be doing the conversion automatically, depending on the operator? Thanks, Barry$x = int (1 + rand 100); print "What is the secret random number? "; while (<STDIN>) { $guess = $_; if ($guess eq "quit") { last; } elsif ($guess == $x) { print "You got it, brother!\n"; last; } elsif ($guess > $x) { print $y; print "Too high! Try again!\n"; } elsif ($guess < $x) { print "Too low! Try again!\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: conversion between numbers and strings?
by ysth (Canon) on Apr 22, 2004 at 04:24 UTC | |
|
Re: conversion between numbers and strings?
by Koosemose (Pilgrim) on Apr 22, 2004 at 04:19 UTC | |
|
Re: conversion between numbers and strings?
by kvale (Monsignor) on Apr 22, 2004 at 04:20 UTC | |
|
Re: conversion between numbers and strings?
by Anonymous Monk on Apr 22, 2004 at 13:40 UTC |