My Brain Is Melting Again!!!!!

Discussion in 'Computer Science & Culture' started by TruthSeeker, Oct 21, 2004.

Thread Status:
Not open for further replies.
  1. TruthSeeker Fancy Virtual Reality Monkey Valued Senior Member

    Messages:
    15,162
    This is my assignment:
    This is what I've got so far....

    private int checkDay(int day, int month, int year){

    int tday,tmonth,tyear;

    switch (month){
    case 1: longMonth(1); break;

    case 2: if ((day>0)&&(day<27)){
    tday=day++;
    }else if (day==28){
    checkLeap(year)
    if (year=leap){
    tday=1;
    tmonth=month++;
    tyear=year;
    }else if (year!=leap){
    tday=day++;
    tmonth=month;
    tyear=year;
    }else if (day==29){
    tday=day++;
    tmonth=month;
    tyear=year;

    break;

    case 3: case 5: case 7: case 8: case 10:
    if ((day>0)&&(day<31)){
    tday=day++;
    tmonth=month;
    tyear=year;
    }else if (day==31){
    tday=1;
    tmonth=month++;
    tyear=year;
    break;


    case 4: case 6: case 9: case 11:
    if ((day>0)&&(day<30)){
    tday=day++;
    tmonth=month++;
    tyear=year;
    }else if (day==30){
    tday=1;
    tmonth=month++;
    tyear=year;
    break;

    case 12: if ((day>0)&&(day<31)){
    tday=day++;
    tmonth=month;
    tyear=year;
    }else if (day==31){
    tday=1;
    tmonth=1;
    tyear=year;
    break;


    return tday,tmonth,tyear;



    }

    //Checking Leap Year
    private boolean checkLeap(int year){

    int leap;

    if (year%4>0)&&(year%400>0)
    year=leap;
    else
    year!=leap

    return leap;

    }


    //Long and Short Months
    private int longMonth(int month){

    int tday,tmonth,tyear;

    if ((day>0)&&(day<31)){
    tday=day++;
    tmonth=month;
    tyear=year;
    }else if (day==31){
    tday=1;
    tmonth=month++;
    tyear=year;
    }

    return tday,tmonth,tyear;
    }

    private int shortMonth (int month){

    int tday,tmonth,tyear;

    if ((day>0)&&(day<30)){
    tday=day++;
    tmonth=month++;
    tyear=year;
    }else if (day==30){
    tday=1;
    tmonth=month++;
    tyear=year;
    }

    return tday,tmonth,tyear;

    }

    It's kinda complicated....

    Please Register or Log in to view the hidden image!


    I'm not sure if it's working properly........

    Please Register or Log in to view the hidden image!


    Can anyone help? Pleeeeeeaaassseeee...
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. TruthSeeker Fancy Virtual Reality Monkey Valued Senior Member

    Messages:
    15,162
    Yuck! It looks horrible without indentation......

    Please Register or Log in to view the hidden image!

     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. TruthSeeker Fancy Virtual Reality Monkey Valued Senior Member

    Messages:
    15,162
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. Blindman Valued Senior Member

    Messages:
    1,425
    Code:
    #include <iostream>
    #include <stdlib.h>
    
    using namespace std;
    // define instruction strings
    #define MONTHINSTRUCTIONS "Enter the month for today's date:" 
    #define MONTHERRORSTRING "You have entered an invalid month.\n"
    #define DAYINSTRUCTIONS "Enter the day for today's date:"
    #define DAYERRORSTRING "You have entered an invalid day.\n"
    #define YEARINSTRUCTIONS "Enter the year for today's date:" 
    #define OUTSTRING "Tomorrow's date is "
    #define DOITONCEMORE "Do you wish to enter a new date ([y]|n)?"
    #define OR ||
    
    // function to get days in a month
    int GetDaysInMonth(int month, int year)
    {
          switch(month)
          {
           case 4:   
           case 6:   
           case 9:   
           case 11:   
               return(30);  // no break needed as the return teminates exicution of this function here
           case 2:
               if(year%4 == 0) // is this a leap year
                   if(year%100 == 0) // is this a centery year
                      if(year%400 ==0) return(29);  // this is a centry leap year
                      else return(28);  //not a leap year
                   else return(29); // leap year
               else return(28);  // normal year
           default: // normal 30 day months
               return(31);
          }  
    }    
    
    void DoDateThing(void)
    {
       
      int month;
      int day;
      int year;
      // get data
    
      cout << YEARINSTRUCTIONS;
      cin >> year;  // get the year first because we need it to vet days in month
    
      bool incorect =true;
      while(incorect)
      {
        cout << MONTHINSTRUCTIONS;
        cin >> month;
        if( month < 1 OR month > 12)
        {
            incorect = true;
            cout << MONTHERRORSTRING;
        }    
        else incorect = false;
      }
      // get date details
      int daysInMonth=GetDaysInMonth(month,year);  
      incorect =  true;
      while(incorect)
      {
          cout << DAYINSTRUCTIONS;
          cin >> day;
    
          if(day < 1 OR day > daysInMonth)
          {
              incorect = true;
              cout << DAYERRORSTRING;
          }    
          else incorect = false;
      }  
    
      // add a day
      day += 1;
      if(day > daysInMonth)
      {
          day = 1;
          month += 1;
          if(month > 12)
          {
              month = 1;
              year += 1;
          }    
      }    
      
      // output result
      cout << OUTSTRING << month << "/" << day << "/" << year << "\n";
    }
      
    int main()
    {
    
        bool dating = true;
        while(dating)
        {
            std::string t;
            DoDateThing();
            cout << DOITONCEMORE;
            cin >> t;
            if(t == "n" OR t == "N") dating = false;
            
        }    
      // pause 
      system("PAUSE");	
      return 0;
    }
    
    Untested but should do the job. May have some syntax errors. Hope this helps.
    5 mins to code, do i get a prize.
     
    Last edited: Oct 21, 2004
  8. c20H25N3o Shiny Heart of a Shiny Child Registered Senior Member

    Messages:
    2,017
    ^^

    Only if you convert the c++ to java in 5 mins

    Please Register or Log in to view the hidden image!

     
  9. alain du hast mich Registered Senior Member

    Messages:
    1,179
    hey, i know very little about computer programming, but here is my idea, instead of having year long cycles, and checking if it is a leap year, have cycles that last 4 years
    1 3 5 7 8 10 12 13 15 17 etc have 31 days
    4 6 9 11 16 18 21 etc have 30 days
    2 14 26 have 28 days
    38 has 29 days

    which i think would simplify it heaps
     
  10. Blindman Valued Senior Member

    Messages:
    1,425
    Opps, to bad, there are plenty of C++ to java utilities out there they should do it in about 1 second.
     
Thread Status:
Not open for further replies.

Share This Page