Hi everyone! This is a very useful program that tells your western zodiac and chinese zodiac signs. This program also tells you the year you born if you enter your current age. I found this program from the stackexchange. I thought it might be helpful for some of our visitors who want to develop something unique with C++. Students can this as a project for their semesters too.

I have also written a Java implementation of this program but for only western zodiac signs. Java implementation follows the C++ program. Please comment if you found this helpful or need any help to run these programs.

Zodiac Signs Program in C++

#include <iostream>
#include <ctime>

int main()
{
    int iZodiac;

    time_t     rawtime;
    struct tm* timeinfo;

    time( &rawtime );
    timeinfo = localtime( &rawtime );

    std::cout << "----Zodiac Program----" << std::endl;

    do {
        std::cout << "\nWhat would you like to do?" << std::endl;
        std::cout << "1.) Chinese Zodiac" << std::endl;
        std::cout << "2.) Western Zodiac" << std::endl;
        std::cout << "3.) Year Born" << std::endl;
        std::cout << "4.) Quit Program" << std::endl;
        std::cin >> iZodiac;

        if (!std::cin || iZodiac <= 0 || iZodiac > 4) {
            std::cin.clear();
            std::cin.ignore(1000, '\n');
            std::cout << "\nI'm sorry but that is not an option. Please answer 1, 2, 3 or 4." << std::endl;
        }


//Start Chinese Zodiac Option
        if (iZodiac == 1) {

            int iCbirth;
            int iCzodiac;

            while ((std::cout << "\nEnter year born." << std::endl) && !(std::cin >> iCbirth)) {
                std::cout << "\nI'm sorry but that is an invalid answer. Please answer using numbers." << std::endl;
                std::cin.clear();
                std::cin.ignore(1000, '\n');
            }

            iCzodiac = iCbirth-((iCbirth/12)*12);

            if (iCzodiac == 0){
                std::cout << "\nYour Chinese Zodiac is the Monkey." << std::endl;
            }
            else if (iCzodiac == 1){
                std::cout << "\nYour Chinese Zodiac is the Rooster." << std::endl;
            }
            else if (iCzodiac == 2){
                std::cout << "\nYour Chinese Zodiac is the Dog." << std::endl;
            }
            else if (iCzodiac == 3){
                std::cout << "\nYour Chinese Zodiac is the Pig." << std::endl;
            }
            else if (iCzodiac == 4){
                std::cout << "\nYour Chinese Zodiac is the Rat." << std::endl;
            }
            else if (iCzodiac == 5){
                std::cout << "\nYour Chinese Zodiac is the Ox." << std::endl;
            }
            else if (iCzodiac == 6){
                std::cout << "\nYour Chinese Zodiac is the Tiger." << std::endl;
            }
            else if (iCzodiac == 7){
                std::cout << "\nYour Chinese Zodiac is the Rabbit." << std::endl;
            }
            else if (iCzodiac == 8){
                std::cout << "\nYour Chinese Zodiac is the Dragon." << std::endl;
            }
            else if (iCzodiac == 9){
                std::cout << "\nYour Chinese Zodiac is the Snake." << std::endl;
            }
            else if (iCzodiac == 10){
                std::cout << "\nYour Chinese Zodiac is the Horse." << std::endl;
            }
            else if (iCzodiac == 11){
                std::cout << "\nYour Chinese Zodiac is the Goat." << std::endl;
            }
        }
//End Chinese Zodiac Option


//Start Western Zodiac Option
        if (iZodiac == 2) {

            int iMonth;
            int iDay;

            while ((std::cout << "\nEnter month born." << std::endl) && !(std::cin >> iMonth)) {
                std::cout << "\nI'm sorry but that is an invalid answer. Please answer using numbers." << std::endl;
                std::cin.clear();
                std::cin.ignore(1000, '\n');
            }
            while ((std::cout << "\nEnter day born." << std::endl) && !(std::cin >> iDay)) {
                std::cout << "\nI'm sorry but that is an invalid answer. Please answer using numbers." << std::endl;
                std::cin.clear();
                std::cin.ignore(1000, '\n');
            }

            if (iMonth == 12) {
                if (iDay >= 22) {
                    std::cout << "\nYour Western Zodiac sign is Capricorn." << std::endl;
                }
                else if (iDay <= 21) {
                    std::cout << "\nYour Western Zodiac sign is Sagittarius." << std::endl;
                }
            }
            else if (iMonth == 11) {
                if (iDay >= 23) {
                    std::cout << "\nYour Western Zodiac sign is Sagittarius." << std::endl;
                }
                else if (iDay <= 22) {
                    std::cout << "\nYour Western Zodiac sign is Scorpio." <<std::endl;
                }
            }
            else if (iMonth == 10) {
                if (iDay >= 23) {
                    std::cout << "\nYour Western Zodiac sign is Scorpio." << std::endl;
                }
                else if (iDay <= 22) {
                    std::cout << "\nYour Western Zodiac sign is Libra." <<std::endl;
                }
            }
            else if (iMonth == 9) {
                if (iDay >= 23) {
                    std::cout << "\nYour Western Zodiac sign is Libra." << std::endl;
                }
                else if (iDay <= 22) {
                    std::cout << "\nYour Western Zodiac sign is Virgo." <<std::endl;
                }
            }
            else if (iMonth == 8) {
                if (iDay >= 23) {
                    std::cout << "\nYour Western Zodiac sign is Virgo." << std::endl;
                }
                else if (iDay <= 22) {
                    std::cout << "\nYour Western Zodiac sign is Leo." <<std::endl;
                }
            }
            else if (iMonth == 7) {
                if (iDay >= 23) {
                    std::cout << "\nYour Western Zodiac sign is Leo." << std::endl;
                }
                else if (iDay <= 22) {
                    std::cout << "\nYour Western Zodiac sign is Cancer." <<std::endl;
                }
            }
            else if (iMonth == 6) {
                if (iDay >= 22) {
                    std::cout << "\nYour Western Zodiac sign is Cancer." << std::endl;
                }
                else if (iDay <= 21) {
                    std::cout << "\nYour Western Zodiac sign is Gemini." <<std::endl;
                }
            }
            else if (iMonth == 5) {
                if (iDay >= 22) {
                    std::cout << "\nYour Western Zodiac sign is Gemini." << std::endl;
                }
                else if (iDay <= 21) {
                    std::cout << "\nYour Western Zodiac sign is Taurus." <<std::endl;
                }
            }
            else if (iMonth == 4) {
                if (iDay >= 21) {
                    std::cout << "\nYour Western Zodiac sign is Taurus." << std::endl;
                }
                else if (iDay <= 20) {
                    std::cout << "\nYour Western Zodiac sign is Aries." <<std::endl;
                }
            }
            else if (iMonth == 3) {
                if (iDay >= 21) {
                    std::cout << "\nYour Western Zodiac sign is Aries." << std::endl;
                }
                else if (iDay <= 20) {
                    std::cout << "\nYour Western Zodiac sign is Pisces." <<std::endl;
                }
            }
            else if (iMonth == 2) {
                if (iDay >= 20) {
                    std::cout << "\nYour Western Zodiac sign is Pisces." << std::endl;
                }
                else if (iDay <= 19) {
                    std::cout << "\nYour Western Zodiac sign is Aquarius." <<std::endl;
                }
            }
            else if (iMonth == 1) {
                if (iDay >= 21) {
                    std::cout << "\nYour Western Zodiac sign is Aquarius." << std::endl;
                }
                else if (iDay <= 20) {
                    std::cout << "\nYour Western Zodiac sign is Capricorn." <<std::endl;
                }
            }
        }
//End Western Zodiac Option


//Start Year Born Option
        if (iZodiac == 3) {
            int iAge;
            int iYear;
            int iBirth;

            iYear = (timeinfo->tm_year + 1900);

            while ((std::cout << "\nEnter your current age." << std::endl) && !(std::cin >> iAge)) {
                std::cout << "\nI'm sorry but that is an invalid answer. Please answer using numbers." << std::endl;
                std::cin.clear();
                std::cin.ignore(1000, '\n');
            }
            iBirth = iYear-iAge;
            std::cout << "\nYou were born in the year " << iBirth << std::endl;
        }
//End Year Born Option


    } while (iZodiac != 4);

    std::cout << "\nThank you for playing, Good bye." << std::endl;

    return 0;
}

Zodiac Signs Program in Java

import java.util.*;
import java.text.DateFormatSymbols;

class TryCalendar
{
	public static void main(String[]args)
	{
		String [] zodiac = {  "CAPRICORN", "AQUARIUS", "PISCES",
		                      "ARIES",     "TAURUS",   "GEMINI",
		                      "CANCER",    "LEO",      "VIRGO",
						              "LIBRA",     "SCORPIO",  "SAGITTARIUS"
						           };

    // Dates for the start of each sign period, starting with Aquarius
    GregorianCalendar[] signStartDates = { 
                                       new GregorianCalendar(2000, Calendar.JANUARY, 21),
		                       new GregorianCalendar(2000, Calendar.FEBRUARY, 20),
		                       new GregorianCalendar(2000, Calendar.MARCH, 21),
		                       new GregorianCalendar(2000, Calendar.APRIL, 21),
		                       new GregorianCalendar(2000, Calendar.MAY, 22),
		                       new GregorianCalendar(2000, Calendar.JUNE, 22),
		                       new GregorianCalendar(2000, Calendar.JULY, 24),
		                       new GregorianCalendar(2000, Calendar.AUGUST, 24),
		                       new GregorianCalendar(2000, Calendar.SEPTEMBER, 24),
		                       new GregorianCalendar(2000, Calendar.OCTOBER, 24),
		                       new GregorianCalendar(2000, Calendar.NOVEMBER, 23),
		                       new GregorianCalendar(2000, Calendar.DECEMBER, 22)
		};
    GregorianCalendar birthday = getDate();           // Get the calendar for a birthday
    String yourSign = zodiac[0];                      // Set CAPRICORN as default
    for(int i = 0; i0 && month<13 && day>0 && day <= monthDays[month-1])
	  	  return new GregorianCalendar(2000, month-1, day);
	  	System.out.println("Invalid date entered. Try again.");
	  }
	  System.out.println("Five invalid dates entered. Sorry - no more tries...");
    System.exit(1);
    return null;
	}

  private static int[] monthDays = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	private static FormattedInput in=new FormattedInput();
}

//******************************************
//FormattedInput.java
//******************************************
import java.io.*;

public class FormattedInput implements Serializable
{
	public String stringRead()
	{
		try
		{
			for(int i=0;i<5;i++)
			{
				int tokenType=tokenizer.nextToken();
				if (tokenType==tokenizer.TT_WORD||tokenType=='\"')
					return tokenizer.sval;
				else if(tokenType=='!')
					return"!";
				else
				{
					System.out.println("Incorrect input. Re-enter a string between double quotes");
					continue;
				}
			}
			System.out.println("Five failures reading a string"+" - program terminated");
			System.exit(1);
			return null;
		}
		catch(IOException e)
		{
			System.out.println(e);
			System.exit(1);
			return null;
		}
	}

	public int intRead()
	{
		try
		{
			for(int i=0; i<5; i++)
			{
				if(tokenizer.nextToken()==tokenizer.TT_NUMBER && tokenizer.nval==(double)((long)tokenizer.nval))
					return(int)tokenizer.nval;
				else
				{
					System.out.println("Incorrect input: "+tokenizer.sval+" Re-enter an integer");
					continue;
				}
			}
			System.out.println("Five failures reading an int value"+" - program terminated");

			System.exit(1);
			return 0;
		}
		catch(IOException e)
		{
			System.out.println(e);
			System.exit(1);
			return 0;
		}
	}
	private StreamTokenizer tokenizer=new StreamTokenizer(new InputStreamReader(System.in));
}

Tagged with: C/C++ languageJAVAProgrammingSource Code
 

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.