Hello there,
Okay i had to write a program that computes the number of days between two dates, right, and so far i'm just sort of stumped over what to do next to get it all right and functioning correctly. I've written the code and everything else, and It runs, but the awnsers not what i'm looking for. Maybe someone can tell me what i'm not doing that i need to be doing. Well i would appreciate your help.
Here's my source code:

// Program 7
// This program computes the number of days between two dates.

#include <iostream>

using namespace std;

int DayCalculation (int month, int day, int year, int month2, int day2, int year2);

int main()
{
      int month;
      int secondMonth;
      int year;
      int day;
      int secondYear;
      int secondDay;
      
      cout << "Enter first dates month ";
      cin >> month;
      
      cout << "Enter second dates month  ";
      cin >> secondMonth;
      
      cout << "Enter the first dates day    ";
      cin >> day;
      
      cout << "Enter the second dates day    ";
      cin >> secondDay;
      
      cout << "Enter the first dates year    ";
      cin >> year;
      
      cout << "Enter the second dates year     ";
      cin >> secondYear;
      
      if (month >= 10 && day >= 15 && year >= 1582)
         
          cout << "The date you entered is invalid";
          
          else 
               DayCalculation ( month, day, year, secondMonth, secondDay,secondYear);
               
         return 0; 
    }
    
    int DayCalculation ( int month, int day, int year, int month2, int day2, int year2)
    
    {
         int result1 = 0;
         int result2;
         int result3;
         
         long JulianDayNumber;
         
         if (month == 1 || month == 2 )
         
         { 
           year--;
           month = month +12;
           }
           
     result1 = 2- year/100+year / 400; // test each one to make sure the right number.
     result2 = int(365.25 * year);
     result3 = int(30.6001 * (month + 1));
     
     JulianDayNumber = result1 + result2 + result3 + day + 1720994.5;
     
     cout << JulianDayNumber << endl;
     
     return 0;
     
     }

...and It runs, but the awnsers not what i'm looking for.

what is the answer? i get these errors when compiling the program:

gcc -o dates dates.cpp
dates.cpp: In function `int DayCalculation(int, int, int, int, int, int)':
dates.cpp:67: warning: converting to `long int' from `double'
/tmp/ccLb60he.o(.text+0x1b): In function `main':
: undefined reference to `std::cout'
/tmp/ccLb60he.o(.text+0x20): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccLb60he.o(.text+0x2e): In function `main':
: undefined reference to `std::cin'
/tmp/ccLb60he.o(.text+0x33): In function `main':
: undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
/tmp/ccLb60he.o(.text+0x42): In function `main':
: undefined reference to `std::cout'
/tmp/ccLb60he.o(.text+0x47): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccLb60he.o(.text+0x55): In function `main':
: undefined reference to `std::cin'
/tmp/ccLb60he.o(.text+0x5a): In function `main':
: undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
/tmp/ccLb60he.o(.text+0x69): In function `main':
: undefined reference to `std::cout'
/tmp/ccLb60he.o(.text+0x6e): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, 

......

Compilation exited abnormally with code 1 at Wed Dec  8 18:28:49

Your code compiles ok on vc++ 6. Your only calculating the julian day number using year, month and day. You need to do the same for year2, month2, day2 and then find the difference between the two julian numbers.

no wonder. i'm using gcc.

just a thought but have you thought using a windows calendar control? it will take into account leap years and will do the calcuations for you...?

for gcc, change <iostream> to <iostream.h> and remove the namespace statement, it might fix errors....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.