User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,905 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,338 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2282 | Replies: 4
Reply
Join Date: Dec 2004
Posts: 11
Reputation: jtxay is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
jtxay jtxay is offline Offline
Newbie Poster

Solution Having a little trouble with my Code. [please Help me out]

  #1  
Dec 8th, 2004
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;
     
     }
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: galveston, texas
Posts: 35
Reputation: serfurj is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
serfurj's Avatar
serfurj serfurj is offline Offline
Light Poster

Re: Having a little trouble with my Code. [please Help me out]

  #2  
Dec 8th, 2004
Originally Posted by jtxay
...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
Reply With Quote  
Join Date: Dec 2004
Posts: 13
Reputation: britt_boy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
britt_boy britt_boy is offline Offline
Newbie Poster

Re: Having a little trouble with my Code. [please Help me out]

  #3  
Dec 9th, 2004
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.
Reply With Quote  
Join Date: Dec 2004
Location: galveston, texas
Posts: 35
Reputation: serfurj is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
serfurj's Avatar
serfurj serfurj is offline Offline
Light Poster

Re: Having a little trouble with my Code. [please Help me out]

  #4  
Dec 9th, 2004
no wonder. i'm using gcc.
Reply With Quote  
Join Date: Dec 2004
Location: Devon - UK
Posts: 420
Reputation: 1o0oBhP is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: Having a little trouble with my Code. [please Help me out]

  #5  
Dec 13th, 2004
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....
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:13 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC