Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:34:02+00:00 2026-06-03T07:34:02+00:00

I was just wondering if anyone noticed i was doing something wrong with my

  • 0

I was just wondering if anyone noticed i was doing something wrong with my code block. Ths program is supposed to be a test program that compares 2 dates. The function that im working on is supposed to return a 1 if the invoking date is greater, a -1 f the invoking date is less than, and a 0 if the invoking date is equal to the date in the parameter. My test Program :

#include <cstdlib>
#include <iostream>
#include <string>

#include "date.h"

using namespace std;

//date is initialized in a month/day/year format.

int main(int argc, char* argv[])
{
    string* d;

    date d1(4,1,4);
    date d4(4,4,4);

    int greaterTest = d4.compareTo(d1);
    int lessTest = d1.compareTo(d4);


    cout << greaterTest << endl;               //i believe these two lines are printing out a
    cout << lessTest << endl;                  //location in memory
    cout<<&d <<endl;


    system("pause");
    return EXIT_SUCCESS;
}

The huge compareTo() function :

    int date::compareTo (date another_date)
{

    if (this->year == another_date.year && this->month == month && this->day < another_date.day)    //if both year and month are the same, test to see if day is less
    {

        return -1;
    }

    else if (this->year == another_date.year && this->month == month && this->day > another_date.day)   //if both year and month are the same, test to see if day is greater
    {

        return 1;
    }


    else if (this->year == another_date.year && this->month > month)                            //if the years are the same, test to see if the invoking month is greater
    {

        return 1;
    }

    else if (this->year == another_date.year && this->month < month)                            //if the years are the same, test to see if the invoking month is less
    {

        return -1;
    }


    else if (this->year > another_date.year)                                                    //test to see if the invoking year is greater
    {

        return 1;
    }

    else if (this->year < another_date.year)                                                    //test to see if the invoking year is less
    {

        return -1;
    }

    else if(this-> year == another_date.year && this-> month == another_date.month                  //test if the dates are exactly the same
        && this-> day == another_date.day)
    {

        return 0;
    } 


    //else{ return 15;}                                                                             //if none are true, return 15


}

the only problem im getting is when i try to change the day (the second parameter for date).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:34:03+00:00Added an answer on June 3, 2026 at 7:34 am

    I’m not sure if this is the problem, since I can’t test it… But, your compareTo function has this line:

    this->month == month
    

    Shouldn’t it be:

    this->month == another_date.month
    

    ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering if anyone knew of any good Calendar libraries for C#? Something that
Just wondering if anyone knows of a C++ library that provides a single interface
just wondering if anyone else has a better suggestion that what I'm coming up
Just wondering if anyone can recommend a .NET library that converts audio formats to
just wondering if anyone knows of a truly restful Put/delete implementation asp.net mvc preview
Just wondering if anyone has any favourite SQL references they to use when creating
Just wondering if anyone knew off the top of their heads if there was
just wondering if anyone could suggest why I might be getting an error? I'm
Just wondering whether anyone knows how to get blogger labels into alt tags in
Just wondering if anyone has any ideas on how we can style templates... Like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.