Thread: Calendar Rage

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    2

    Calendar Rage

    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std;
    main()
    {
    int month,day,year;
    cout <<endl;
    cout <<"Enter The Month Of Your Birthday:"<<endl<<"1=Jan 2=Feb 3=Mar 4=Apr 5=May 6=Jun 7=Jul 8=Aug 9=Sep 10=Oct 11=Nov 12=Dec: ";
    cin >>month;
    	
    cout <<endl;
    cout <<"Enter The Day Of Your Birthday:"<<endl<<" 1 - 31: ";
    cin >>day;
    
    cout <<endl;
    cout <<"Enter The Year Of Your Birthday:"<<endl<<"80's - 06's: ";
    cin >>year;
    
    if (month = 1)
    {
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Aquarius";
    }
    if (month = 2)
    {
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Pisces";
    }
    if (month = 3)
    {
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Aries";
    }
    if (month = 4)
    {
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Taurus";
    }
    if (month = 5)
    {	
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Gemini";
    }
    if (month = 6)
    {
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Cancer";
    }
    if (month = 7)
    {	
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Leo";
    }
    if (month = 8)
    {
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Virgo";
    }
    if (month = 9)
    {
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Libra";
    }
    if (month = 10)
    {
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Scorpio";
    }
    if (month = 11)
    {
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Sagitarius";
    }
    if (month = 12)
    {
    cout <<"Because your birthday is "<<month<<"/"<<day<<"/"<<year<<" your zodiac sign is Capricorn";
    }
    
    getch();
    }
    I have a problem with this i cant make a range of the birthdates ... like january 1 upto february 19 is aquarius ..... Feb. 20 - Mar. 20 is pisces and so on ....... i also try switch case but ... case is only read integer ....

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Code:
    if (month = 1)
    Think hard about what the above code does.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Yeah, I get angry at the calendar sometimes as well.

    In the meantime, you might want to replace all those = in your if statements with ==
    If you're a mingw / dev-c++ user, then add "-W -Wall" to the compiler command line options.

    Then remove that conio.h and swing by the FAQ to find other ways of keeping the console window on screen at the end of the program.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    2
    But how can i make some range on it ... like january 1 upto february 19 is aquarius ..... Feb. 20 - Mar. 20 is pisces ....

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Like
    if ( month == 1 && day <= 21 )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Code:
    main
    should really be

    Code:
    int main ( void )
    Also, try to indent your code, it makes for much easier reading and debugging
    Double Helix STL

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    22
    sry just a question I get confused sometimes on when to use cout<<endl can someone explain and use an example? this topic sheds some light though

  8. #8
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    cout << endl (or std::cout << std::endl) outputs a newline to the output buffer. endl expands to endline. And don't hijack other people's threads with your questions. Start your own.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It also flushes the buffer, which is often unnecessary but rarely harmful. You can use cout << '\n' instead.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    In other words, cout << endl is the same as cout << '\n' << flush.

    If you know how to use arrays (or even functions), you could simplify that code a lot.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing a program to make a calendar
    By Northstar in forum C Programming
    Replies: 17
    Last Post: 11-07-2007, 11:34 AM
  2. how to convert from solar calendar to lunar calendar??
    By zaracattle in forum C++ Programming
    Replies: 7
    Last Post: 11-30-2006, 07:17 AM
  3. calendar program for linux
    By *ClownPimp* in forum Tech Board
    Replies: 1
    Last Post: 10-01-2005, 02:31 AM
  4. writing a calendar program help please!!!
    By Newbie2006 in forum C Programming
    Replies: 7
    Last Post: 11-20-2002, 07:36 PM