C++ Programmers

Discussion in 'OT Technology' started by Sex Machine, Dec 4, 2003.

  1. Sex Machine

    Sex Machine New Member

    Joined:
    Jun 26, 2003
    Messages:
    17,759
    Likes Received:
    0
    Location:
    SoCal
    What am I doing wrong?

    Code:
    #include <iostream.h>
    #include <string.h>
    class Date
    {
    private:
     int month;
     int day;
     int year;
    public:
     void setDate(int month1,int day1, int year1);
     void showDate();
     int increaseDay(int day1);
    };
    void Date::setDate(int month1, int day1, int year1)
    {
     if (day1 > 30)
     {
      day = 1;
      month1++;
     }
     else
      day = day1;
     if (month1 > 12)
      month = 12;
     else
      month = month1;
     year = year1;
    }
    void Date::showDate()
    {
     cout<<endl<<month<<"/"<<day<<"/"<<year<<endl;
    }
    
    int Date::increaseDay(int day1)
    {
     day1++;
     day = day1;
     return day1;
    }
    void main ()
    {
     Date aDate;
     int month1 =10;
     int day1 = 29;
     int year1 = 2003;
     int x = 0;
    // cout<<"Enter a numerical Month: ";
    // cin>>month1;
    // cout<<endl<<"Enter a numerical Day: ";
    // cin>>day1;
    // cout<<endl<<"Enter a year: ";
    // cin>>year1;
     for (x = 0; x < 5; x++)
     {
      
      aDate.setDate(month1, day1, year1);
      aDate.showDate();
      day1 = aDate.increaseDay(day1);
     }
     
    }
     


    This is what I get

    [​IMG]
     
    Last edited by a moderator: Dec 4, 2003
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    repost your code in the [ code ] tags i just added to your post. It's hard to read mang
     
  3. Sex Machine

    Sex Machine New Member

    Joined:
    Jun 26, 2003
    Messages:
    17,759
    Likes Received:
    0
    Location:
    SoCal
    Code:
     #include <iostream.h>
    #include <string.h>
    class Date
    {
    private:
     int month;
     int day;
     int year;
    public:
     void setDate(int month1,int day1, int year1);
     void showDate();
     int increaseDay(int day1);
    };
    void Date::setDate(int month1, int day1, int year1)
    {
     if (day1 > 30)
     {
      day = 1;
      month1++;
     }
     else
      day = day1;
     if (month1 > 12)
      month = 12;
     else
      month = month1;
     year = year1;
    }
    void Date::showDate()
    {
     cout<<endl<<month<<"/"<<day<<"/"<<year<<endl;
    }
    
    int Date::increaseDay(int day1)
    {
     day1++;
     day = day1;
     return day1;
    }
    void main ()
    {
     Date aDate;
     int month1 =10;
     int day1 = 29;
     int year1 = 2003;
     int x = 0;
    // cout<<"Enter a numerical Month: ";
    // cin>>month1;
    // cout<<endl<<"Enter a numerical Day: ";
    // cin>>day1;
    // cout<<endl<<"Enter a year: ";
    // cin>>year1;
     for (x = 0; x < 5; x++)
     {
      
      aDate.setDate(month1, day1, year1);
      aDate.showDate();
      day1 = aDate.increaseDay(day1);
     }
     
    }
    
     
  4. toolfreek

    toolfreek Guest

    see my answer in the main forum....your problem is that though you are resetting the date locally for the class, it is not making it back out to your main variables, which should be eliminated anyway.
     
  5. Sex Machine

    Sex Machine New Member

    Joined:
    Jun 26, 2003
    Messages:
    17,759
    Likes Received:
    0
    Location:
    SoCal
    thank you
     
  6. toolfreek

    toolfreek Guest

    no prob...let me know if you need more help/guidance in getting set up correctly.
     

Share This Page