need help with this problem

This is a discussion on need help with this problem within the C Programming forums, part of the General Programming Boards category; Write an astrology program. The user types in a birthday, and the program responds with the sign and horoscope for ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    3

    need help with this problem

    Write an astrology program.

    The user types in a birthday, and the program responds with the sign and horoscope for that birthday. The month may be entered as a number from 1 to 12. Then, enhance your program so that if the birthday is only one or two days away from an adjacent sign, the program announces that the birthday is on a “cusp” and also outputs the horoscope for that nearest adjacent sign.

    This program will have a long multiway branch. Make up a horoscope for each sign. Your program should include a loop that lets the user repeat this calculation until the user says she or he is done.

    The horoscope signs and dates are:
    Sign Dates
    Aries March 21 – April 19
    Taurus April 20 – May 20
    Gemini May 21 – June 21
    Cancer June 22 – 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
    Capricorn December 22 – January 19
    Aquarius January 20 – February 18
    Pisces February 19 – March 20


    Code:
    //Header file section
    #include<stdio.h>
    //Begin main function
    int main (void)
    {
    //Variable declartion
    int month, date;
    int startdate,startmonth,enddate,endmonth;
    char continues;
    do
    {
    //Inputting day
    printf("Enter the day of month for your birthday\n");
    scanf("%d",date);
    //Inputting month
    printf(" Entre month of your birthday\n");
    scanf("%d",month);
         if(month>12 || date>31)
         printf("Invalid input\n");
    
    {
    startdate = 21;
    enddate = 19;
    startmonth = 3;
    endmonth = 4;
         if(( month == startmonth && date >= startdate)||(month == endmonth && date <= enddate))
    {
         printf("Your Sign is : aries \n");
         if(date >= enddate-3 && month == endmonth)
         printf("you are a cusp baby and with adjacent sign: Taurus \n");
         else if(date <= startdate +3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign: Pieces \n");
    }
    startdate = 20;
    enddate = 20;
    startmonth = 4;
    endmonth = 5;
         if(( month == startmonth && date>= startdate)||(month ==endmonth && date <= enddate))
    {
         printf("Your Sign is : Taurus\n");
         if(date >= enddate - 3 && month == endmonth)
         printf(" you are a cusp baby and with adjacent sign: Gemini \n");
         else if(date <= startdate + 3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign: Aries \n");
    }
    startdate = 21;
    enddate = 21;
    startmonth = 5;
    endmonth = 6;
         if(( month == startmonth && date >= startdate)||(month == endmonth && date <= enddate))
    {
         printf("Your Sign is : Gemini\n");
         if(date >= enddate - 3 && month == endmonth)
         printf("you are a cusp baby and with adjacent sign:Cancer \n");
         else if(date <= startdate + 3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign:Taurus \n");
    }
    startdate = 22;
    enddate = 22;
    startmonth = 6;
    endmonth = 7;
         if(( month == startmonth && date >= startdate)||(month == endmonth && date <= enddate))
    {
         printf("Your Sign is : Cancer\n");
         if(date >= enddate - 3 && month == endmonth)
         printf("you are a cusp baby and with adjacent sign: Leo\n");
         else if(date <= startdate + 3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign: Gemini\n");
    }
    startdate = 23;
    enddate = 22;
    startmonth = 7;
    endmonth = 8;
         if(( month == startmonth && date >= startdate)||(month == endmonth && date <= enddate))
    {
         printf("Your Sign is : Leo\n");
         if(date >= enddate - 3 && month == endmonth)
         printf("you are a cusp baby and with adjacent sign: Virgo\n");
         else if(date <= startdate + 3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign: Cancer\n");
    }
    startdate = 23;
    enddate = 22;
    startmonth = 8;
    endmonth = 9;
         if(( month == startmonth && date>= startdate)||(month == endmonth && date <= enddate))
    {
         printf("Your Sign is : Virgo\n");
         if(date >= enddate - 3 && month == endmonth)
         printf("you are a cusp baby and with adjacent sign: Libra\n");
         else if(date <= startdate + 3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign: Leo\n");
    }
    startdate = 23;
    enddate = 22;
    startmonth = 9;
    endmonth = 10;
         if(( month == startmonth && date>= startdate)||(month ==endmonth && date <= enddate))
    {
         printf("Your Sign is : Libra\n");
         if(date >= enddate - 3 && month == endmonth)
         printf("you are a cusp baby and with adjacent sign: Scorpio\n");
         else if(date <= startdate + 3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign: Virgo\n");
    }
    startdate =23;
    enddate = 21;
    startmonth = 10;
    endmonth = 11;
         if(( month== startmonth && date>= startdate)||(month == endmonth && date <= enddate))
    {
         printf("Your Sign is :Scorpio\n");
         if(date >= enddate - 3 && month == endmonth )
         printf("you are a cusp baby and with adjacent sign: Sagitarius\n");
         else if(date <= startdate + 3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign: Libra\n");
    }
    startdate =22;
    enddate = 21;
    startmonth = 11;
    endmonth = 12;
         if(( month== startmonth && date>= startdate)||(month == endmonth && date <= enddate))
    {
         printf("Your Sign is :Sagittarius\n");
         if(date >= enddate - 3 && month == endmonth)
         printf("you are a cusp baby and with adjacent sign: Sagitarius\n");
         else if(date <= startdate + 3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign: Libra\n");
    }
    startdate = 22;
    enddate = 19;
    startmonth = 12;
    endmonth = 1;
         if(( month== startmonth && date>= startdate)||(month ==endmonth && date <= enddate))
    {
         printf("Your Sign is : Capricorn\n");
         if(date >= enddate - 3 && month == endmonth)
         printf("you are a cusp baby and with adjacent sign: Aquarius\n");
         else if(date <= startdate +3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign:Sagittarius\n");
    }
    startdate = 20;
    enddate = 18;
    startmonth = 1;
    endmonth = 2;
         if(( month== startmonth && date>= startdate)||(month ==endmonth && date <= enddate))
    {
         printf("Your Sign is : Aquarius\n");
         if(date>= enddate - 3 && month == endmonth)
         printf("you are a cusp baby and with adjacent sign: Pisces\n");
         else if(date <= startdate + 3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign: Capricorn\n");
    }
    startdate = 19;
    enddate = 20;
    startmonth = 2;
    endmonth = 3;
         if(( month == startmonth && date >= startdate)||(month == endmonth && date <= enddate))
    {
         printf("Your Sign is : Pieces\n");
         if(date >= enddate - 3 && month == endmonth)
         printf("you are a cusp baby and with adjacent sign:Aries\n");
         else if(date <= startdate + 3 && month == startmonth)
         printf("you are a cusp baby and with adjacent sign: Aquarius \n");
    }
    }
    printf(" To repeat calculations for different variables then press 'y' or 'Y'\n");
    scanf("%s",continues);
    } while(continues=='y' || continues =='Y');
    return 0;
    }//End main function
    I can compile the program and run it. But when i enter the input, the error window pop up. Anyone can help me to find out the problem?

  2. #2
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    It's &month and &date for scanf().

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    3
    thank you so much msh
    apparently i found out that my loop is not working as well, how to solve it?

  4. #4
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    How about you check all your scanf()'s first? Like the one at the end. There's two mistakes in it.

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    3
    oh for the first mistake, i get it, it should be &continues. What's the second mistake?

  6. #6
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Read your documentation for scanf(). %s is for getting a string, and if you want to get a string, you need either an array to put it into, or some dynamically allocated memory. Also, for strings, you do not use the 'address of' operator (&) before the name. Since you are looking for a single character, and not a string ('y' or 'Y'), I would suggest that you just do scanf("%c", &some_variable);

    Having said all of this, I would suggest that you not use scanf() at all. There are other, less problematic, functions available for getting user input. Have a look at the board FAQ for some ideas.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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