programmercarlito has asked for the wisdom of the Perl Monks concerning the following question:
Wondering how to get just numbers.So far it seems to work for the first two paragraphs of code but when it gets to the third piece it just doesnt seem to work.The if and else statement dont work. Dont worry about the last 3. I havent modified those to my liking yet. Thanks
print"Enter the starting amount: "; $startAmount = <stdin>; while($startAmount == ""){ print"Numbers only! Try again: "; $startAmount = <stdin>; };chomp($startAmount); print"Enter your current age: "; $startAge = <stdin>; while($startAge == ""){ print"Numbers only! Try again: "; $startAge = <stdin>; };chomp($startAge); print"Enter the age you want to retire: "; $endAge = <stdin>; while($endAge == ""){ if($endAge >= $startAge){ print"Age you want to retire must be greater than current age\n"; $endAge = <stdin>; }#ends if else{ print"Numbers only! Try again: "; $endAge = <stdin>; }#ends else };chomp($endAge); print "Enter amount deposited per year: "; $yearlyDeposit = <stdin>; chomp($yearlyDeposit); print "Enter the Annual interest rate: "; $annualInterest = <stdin>; chomp($annualInterest); print "Enter Expected Retirement Money: "; $expectedMoney = <stdin>; chomp($expectedMoney); system("pause");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Stdin for just numbers
by Athanasius (Archbishop) on Mar 16, 2015 at 01:13 UTC | |
|
Re: Stdin for just numbers.
by graff (Chancellor) on Mar 16, 2015 at 02:01 UTC | |
by BillKSmith (Monsignor) on Mar 16, 2015 at 13:30 UTC | |
by AppleFritter (Vicar) on Mar 16, 2015 at 17:10 UTC | |
by davido (Cardinal) on Mar 16, 2015 at 20:02 UTC | |
|
Re: Stdin for just numbers.
by LanX (Saint) on Mar 16, 2015 at 01:03 UTC | |
|
Re: Stdin for just numbers.
by shmem (Chancellor) on Mar 16, 2015 at 14:48 UTC | |
|
Re: Stdin for just numbers. (use Getopt::Long)
by jeffa (Bishop) on Mar 16, 2015 at 16:53 UTC |