Example 17: Display Zodiac Sign

Learn how to print a Zodiac sign based on your date of birth.

Problem

Write a program that receives the month and date of birth as input and prints the corresponding Zodiac sign based on the following table:

Zodiac Sign From – To
Capricorn December 22 – January 19
Aquarius January 20 – February 17
Pisces February 18 – March 19
Aries March 20 – April 19
Taurus April 20 – May 20
Gemini May 21 – June 20
Cancer June 21 – July 22
Leo July 23 – August 22
Virgo August 23 – September 22
Libra September 23 – October 22
Scorpio October 23 – November 21
Sagittarius November 22 – December 21

Example

Input (Day , Month) Output
10 , 3 Pisces
28 , 12 Capricorn
32 , 11 Invalid Input

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.