Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# program problem

Posted on 2000-04-18
Medium Priority
217 Views
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.
0
Question by:myoreorex
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 16

Accepted Solution

maneshr earned 200 total points
ID: 2727869
try this...........

#!/usr/local/bin/perl

@yrs=("Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Roo
ster","Dog","Pig");

\$sign_change=11;

print "Enter a year between 1900 & 2099 ";
\$year=<STDIN>;
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";
exit;
}

\$sign=\$year-1900;

while(\$sign>\$sign_change){
\$sign-=scalar @yrs;
}

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

if (\$yrs[\$sign]=~ /^Rabbit\$/){
print "Cat";
}
0

Author Comment

ID: 2727905
Ok...I left out the chomp...thats where I went wrong.  Thanks!

Michelle
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
###### Suggested Courses
Course of the Month7 days, 18 hours left to enroll