program problem

1 Write a program in perl that prompts and restricts the user to any year between 1900
  and 2099, and for that year prints the sign of the Chinese Zodiac. Your
  solution can only use "if-elsif-else" type statements to implement the
  selections.  There are twelve signs in the Chinese Zodiac and they are,
  in order:

  Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig

  In addition, the Cat is used instead of the Rabbit in Vietnamese culture. If
  the year maps to Rabbit, print both.

  This sequence, starting with Rat, begins in the year 1900.  As a test, this
  year, 2000 is Year of the Dragon.
Who is Participating?
maneshrConnect With a Mentor Commented:
try this...........




print "Enter a year between 1900 & 2099 ";
chomp($year); ## Remove the \n from the users input
$year=~ s/\s+//g; ## Remove any white spaces from the user's input.
if ($year<1900 || $year >2099){
  print "Year can ONLY be between 1900 and 2099\n";


  $sign-=scalar @yrs;

print "$year is the year of $yrs[$sign] ";

if ($yrs[$sign]=~ /^Rabbit$/){
  print "Cat";
myoreorexAuthor Commented:
Ok...I left out the chomp...thats where I went wrong.  Thanks!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.