Like Tree1Likes
  • 1 Post By AndiPersti

Please check my Zodiac Program

This is a discussion on Please check my Zodiac Program within the C Programming forums, part of the General Programming Boards category; Hello. I am a beginner trying to write a program that would state a user's chinese zodiac and horoscope sign ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    2

    Please check my Zodiac Program

    Hello. I am a beginner trying to write a program that would state a user's chinese zodiac and horoscope sign after inputing his or her birthday.

    I have been, however, having trouble getting the program to run correctly. Any suggestions would be much appreciated!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdbool.h>
    
    #define CAPRICORN  ‘G’
    #define AQUARIUS ‘W’
    #define PISCES ‘F’
    #define ARIES ‘R’
    #define TAURUS ‘B’
    #define GEMNI ’T’
    #define CANCER ‘C’
    #define LEO ‘L’
    #define VIRGO ‘V’
    #define LIBRA ’S’
    #define SCORPIO ’N’
    #define SAGITTARIUS ‘A’
    
    #define MINYEAR 1900
    #define MAXYEAR 2013
    
    
    
    void getCode (char *sun, char *zodiac, int month, int day, int year);
    void printOutput ();
    
    int calcSun (int month, int day);
    char calcZodiac (int year, int month, int day);
    
    float sunresult (char sun);
    float zodiacresult (char zodiac);
    
    bool isLeapYear (int year);
    
    
    int main(void)
    {
        int day, month, year;
        char sun, zodiac;
    
        
        
        
        printf("\nEnter your birthdate: MM DD YYYY: ");
        scanf("%d %d %d", &month, &day, &year );
        
        
        getCode (&sun, &zodiac, day, month, year);
        printOutput ();
    }
    
    
    
    
    
    void getCode (char *sun, char *zodiac, int day, int month, int year)
    
    {
        
        *sun = calcSun (month, day);
        *zodiac = calcZodiac(year, month, day);
        
    }
    
    
    int calcSun (int month, int day)
    {
        
        float sun;
        
        switch (month)
        {
            case 1:
                if(day >= 1 && day <= 19)
                {
                    sun = 'G';
                }
                else if (day>=20 && day<=31)
                {
                    sun = 'W';
                }
                else
                {
                    sun = 'Z';
                }
                break;
                
                
            case 2:
            {if (day>=1 && day<=18)
            {
                sun = 'W';
            }
                if(day>=19 && day<=28)
                {
                    sun = 'F';
                }
                else if (day==29 && isLeapYear(true))
                {
                    sun = 'F';
                }
                else
                {
                    sun = 'Z';
                }}
                break;
                
                
                
            case 3:
            {if (day>=1 && day<=20)
            {
                sun = 'F';
            }
            else if (day>21 && day<=30)
            {
                sun = 'R';
            }
            else
            {
                sun = 'Z';
            }}
                break;
                
                
            case 04:
            { if (day>=1 && day<=19)
            {
                sun = 'R';
            }
            else if(day>=20 && day <= 30)
            {
                sun = 'B';
            }
            else
            {
                sun = 'Z';
            }}
                break;
                
                
            case 5:
            {
                if (day>=1 && day <=20)
                {
                    sun = 'B';
                }
                else if(day>=21 && day <=31)
                {
                    sun = 'T';
                }
                else
                {
                    sun = 'Z';
                }
            }
                break;
                
                
            case 6:
            {
                if (day>=1 && day<=20)
                {
                    sun = 'T';
                }
                else if(day >=22 && day<=30)
                {
                    sun = 'C';
                }
                else
                {
                    sun = 'Z';
                }
            }
                break;
                
                
            case 7:
            {
                if (day>=1 && day<=22)
                {
                    sun = 'C';
                }
                else if (day>=23 && day <=31)
                {
                    sun = 'L';
                }
                else
                {
                    sun = 'Z';
                }
            }
                break;
                
            case 8:
            {
                if (day>=1 && day <=22)
                {
                    sun = 'L';
                }
                else if (day>= 23 && day <= 31)
                {
                    sun = 'V';
                }
                else
                {
                    sun = 'Z';
                }}
                break;
                
                
            case 9:
            {
                if (day>=1 && day<=22)
                {
                    sun = 'V';
                }
                else if(day>=23 && day <=30)
                {
                    sun = 'S';
                }
                else
                {
                    sun = 'Z';
                }
            }
                break;
                
                
            case 10:
            {
                if (day>=1 && day<=22)
                {
                    sun = 'S';
                }
                else if (day>=23 && day<=31)
                {
                    sun = 'N';
                }
                else
                {
                    sun = 'Z';
                }
            }
                break;
                
                
            case 11:
            {
                if (day>=1 && day<=21)
                {
                    sun = 'N';
                }
                else if(day>=22 || day<= 30)
                {
                    sun = 'A';
                }
                else
                {
                    sun = 'Z';
                }
            }
                break;
                
                
            case 12:
            {
                if (day>=1 && day<=21)
                {
                    sun = 'A';
                }
                else if(day>=22 && day<=31)
                {
                    sun = 'G';
                }
                else
                {
                    sun = 'Z';
                }}
                break;
                
                
                
                
                
                
                
        }
        return sun;
    }
    
    
    char calcZodiac (int year, int month, int day)
    {
        float zodiac;
        
        if ( year < MINYEAR && year >MAXYEAR)
        {
                zodiac = -1;
                return zodiac;
        }
        else if (month == 1 || (month == 2 && day<=5))
                {
                    year --;
                    zodiac = (year-4)%12;
                    return zodiac;
                }
              else
                {
                zodiac = (year-4)%12;
                return zodiac;
                }
            }
    
    
    
    void printOutput (int month, int day)
    {
        char sun;
        char zodiac;
        
        sunresult(&sun);
        zodiacresult(&zodiac);
            if ( ((month == 1) && (day>=21 && day <= 31)) || ((month ==2)&&(day>=1 &&day<=5)))
            {
                printf("\nOR you may be\n");
                zodiac = ((zodiac+1)%12);
                zodiacresult(zodiac);
            }
        if ((month==2)&&(day>=6 && day <=20))
        {
            printf("\nOR you may be\n");
            zodiac --;
            zodiacresult(zodiac);
        }
        
          
    }
    
        float sunresult(char sun)
    {
        switch (sun)
            {
                case 'G': printf("\nYour Sun Sign is Capricorn - The Goat"
                                 "Capricorn’s are also philosophical signs and are highly intelligent too."
                                 "They are good organizers, and they achieve their goals by purposeful,"
                                 "systematic means.");
                        break;
                case 'W': printf("\nYour Sun Sign is Aquarius - The Water Bearer"
                                 "Aquarian’s will take up any cause, and are humanitarians of the zodiac."
                                 "They are honest, loyal and highly intelligent.");
                        break;
                case 'F': printf("\nYour Sun Sign is Pisces - The Fish"
                                 "They are honest, unselfish, trustworthy and often have quiet dispositions."
                                 "They can be overcautious and sometimes gullible.");
                        break;
                case 'R': printf("\nYour Sun Sign is Aries - The Ram"
                                 "Aries people are creative, adaptive, and insightful. Aries are fire signs, and"
                                 "so too is their personality.");
                        break;
                case 'B': printf("\nYour Sun Sign is Taurus - The Bull"
                                 "Stubborn by nature, the Taurus will stand his/her ground to the bitter end."
                                 "But that’s okay because the Taurus is also a loving, sympathetic and"
                                 "appreciative sign.");
                        break;
                case 'T': printf("\n  Your Sun Sign is Gemini - The Twins"
                                 "Flexibility, balance and adaptability are the keywords for the Gemini. They"
                                 "tend to have a duality to their nature, and can sometimes be tough to predict"
                                 "how they will react.");
                        break;
                case 'C': printf("\nYour Sun Sign is Cancer - The Crab"
                                 "Cancerians love home-life, family and domestic settings. They are"
                                 "traditionalists, and enjoy operating on a fundamental level. ");
                case 'L': printf("\nYour Sun Sign is Leo - The Lion"
                                 "The zodiac signs and meanings of Leo is about expanse, power and"
                                 "exuberance. Leo’s are natural born leaders, and have a tendency to be"
                                 "high-minded and vocal about their opinions. ");
                        break;
                case 'V': printf("\nYour Sun Sign is Virgo - The Virgin"
                                 "Virgo’s have keen minds, and are delightful to talk with, often convincing"
                                 "others of outlandish tales with ease and charm. Virgo’s are inquisitive and"
                                 "are very skilled at drawing information from people. ");
                        break;
                case 'S': printf("\nYour Sun Sign is Libra - The Scales"
                                 "As their zodiac signs and meanings would indicate, Libra’s are all about"
                                 "balance, justice, equanimity and stability.  Libra’s are very understanding,"
                                 "caring, and often the champion of underdogs.");
                        break;
                case 'N': printf("\nYour Sun Sign is Scorpio - The Scorpion"
                                 "The Scorpio is often misunderstood. These personalities are bold and are"
                                 "capable of executing massive enterprises with cool control and confidence." );
                        break;
                case 'A': printf("\n’A’:  Your Sun Sign is Sagittarius - The Archer"
                                 "They have great ability for focus, and can be very intense.  They are not very"
                                 "patient and expect quick results.");
                        break;
                default: printf("\nInvalid Birthdate");
                    
            }
        return 0;
    }
    
    
    float zodiacresult (char zodiac)
    {
        switch(zodiac)
            {
                case 0: printf("\nYour Chinese Zodiac sign is the Rat"
                                 "Those born under the Chinese Zodiac sign of the Rat are quick-witted, clever,"
                                 "charming, sharp and funny. ");
                    break;
                case 1: printf("\nYour Chinese Zodiac sign is the Ox"
                                 "The Ox is steadfast, solid, a goal-oriented leader, detail-oriented, hard-working,"
                                 "stubborn, serious and introverted but can feel lonely and insecure.  ");
                    break;
                case 2: printf("\nYour Chinese Zodiac sign is the Tiger"
                                 "The Tiger is authoritative, self-possessed, have strong leadership qualities, is"
                                 "charming, ambitious, courageous, warm-hearted, highly seductive, moody,"
                                 "intense, and ready to pounce at any time.");
                    break;
                case 3: printf("\nYour Chinese Zodiac sign is the Rabbit"
                                "Those born under the Chinese Zodiac sign of the Rabbit are popular,"
                                "compassionate, sincere, and they like to avoid conflict and are sometimes seen"
                                "as pushovers.");
                    break;
                case 4: printf("\nYour Chinese Zodiac sign is the Dragon"
                                 "A powerful sign, those born under the Chinese Zodiac sign of the Dragon are"
                                 "energetic and warm-hearted, charismatic, lucky at love and egotistic." );
                    break;
                case 5: printf("\nYour Chinese Zodiac sign is the Snake"
                                 "The Snake is seductive, gregarious, introverted, generous, charming, good with"
                                 "money, analytical, insecure, jealous, slightly dangerous, smart, they rely on gut"
                                 "feelings, are hard-working and intelligent. ");
                    break;
                case 6: printf("\nYour Chinese Zodiac sign is the Horse"
                                 "Those born under the Chinese Zodiac sign of the Horse love to roam free."
                                 "They’re energetic, self-reliant, money-wise, and they enjoy traveling, love and"
                                 "intimacy. ");
                    break;
                case 7: printf("\nYour Chinese Zodiac sign is the Goat"
                                 "Those born under the Chinese Zodiac sign of the Goat are creative, thinkers,"
                                 "wanderers, unorganized, high-strung and insecure, and can be anxiety-ridden." );
                    break;
                case 8: printf("\nYour Chinese Zodiac sign is the Monkey"
                                 "Those born under the Chinese Zodiac sign of the Monkey thrive on having fun."
                                 "They’re energetic, upbeat, and good at listening but lack self-control. ");
                    break;
                case 9: printf("\nYour Chinese Zodiac sign is the Rooster"
                                 "The Rooster is practical, resourceful, observant, analytical, straightforward,"
                                 "trusting, honest, perfectionists, neat and conservative. ");
                    break;
                    
                case 10: printf("\nYour Chinese Zodiac sign is the Dog"
                                  "The Dog is loyal, faithful, honest, distrustful, often guilty of telling white lies,"
                                  "temperamental, prone to mood swings, dogmatic, and sensitive. ");
                    break;
                    
                case 11: printf("\nYour Chinese Zodiac sign is the Pig"
                                  "The Pig is extremely nice, good-mannered and tasteful. They’re perfectionists"
                                  "who enjoy finer things but are not perceived as snobs." );
                    break;
                    
                default: printf("\nINVALID BIRTHDATE");
            }
        return 0;
    }
                  
    bool isLeapYear(int year)
                  {
                      if( (year % 4 ==0 && year %100 !=0) ||
                         year % 400==0 )
                          return true;
                      else
                          return false;
                  }

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Miso Wong View Post
    I have been, however, having trouble getting the program to run correctly. Any suggestions would be much appreciated!
    A problem description would be much appreciated.
    "having trouble getting the program to run correctly" is not a problem description.

    Compiling with warnings will probably help too.

    Bye, Andreas
    Salem likes this.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    2
    Quote Originally Posted by AndiPersti View Post
    A problem description would be much appreciated.
    "having trouble getting the program to run correctly" is not a problem description.

    Compiling with warnings will probably help too.

    Bye, Andreas
    There are no remaining compilation warnings if that's what you mean. Lets say I input 07/31/1993, the code automatically skips the switch and if-else statements and automatically goes to default. "Invalid Birthday". I really don't know what could be going wrong. Any help would be appreciated.

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Miso Wong View Post
    There are no remaining compilation warnings
    You're sure?
    Code:
    $ make foo
    cc -ggdb3 -Wall -Wextra    foo.c   -o foo
    foo.c: In function ‘printOutput’:
    foo.c:321:5: warning: passing argument 1 of ‘sunresult’ makes integer from pointer without a cast [enabled by default]
    foo.c:29:7: note: expected ‘char’ but argument is of type ‘char *’
    foo.c:322:5: warning: passing argument 1 of ‘zodiacresult’ makes integer from pointer without a cast [enabled by default]
    foo.c:30:7: note: expected ‘char’ but argument is of type ‘char *’
    foo.c: In function ‘main’:
    foo.c:49:1: warning: control reaches end of non-void function [-Wreturn-type]
    So you either need to learn to use your tools or change them if they don't work.

    Most of your problems I've noticed are about changing types on the fly. E.g.
    Code:
    void getCode (char *sun, char *zodiac, int day, int month, int year)
    {
        *sun = calcSun (month, day);
        *zodiac = calcZodiac(year, month, day);
    }
    
    int calcSun (int month, int day)
    {
        float sun;
        
        switch (month)
        {
            case 1:
                if(day >= 1 && day <= 19)
                {
                    sun = 'G';
    ...
        return sun;
    "sun" in getCode() is a char *, but you have defined calcSun() to return an int which is not true because inside that function "sun" is a float to which you assign a character.

    Bye, Andreas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. amw real life cryptology zodiac
    By kryptkat in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 12-17-2007, 09:31 AM
  2. Zodiac, reincarnation, phantasmas --> 4
    By AProg in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 07-10-2003, 07:49 PM
  3. Zodiac, reincarnation, phantasmas --> 3
    By AProg in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 07-10-2003, 01:05 PM
  4. Zodiac, reincarnation, phantasmas --> 2
    By AProg in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-10-2003, 06:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21