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

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2004
Posts: 11
Reputation: jtxay is an unknown quantity at this point 
Solved Threads: 0
jtxay jtxay is offline Offline
Newbie Poster

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

 
0
  #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:

  1. // Program 7
  2. // This program computes the number of days between two dates.
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. int DayCalculation (int month, int day, int year, int month2, int day2, int year2);
  9.  
  10. int main()
  11. {
  12. int month;
  13. int secondMonth;
  14. int year;
  15. int day;
  16. int secondYear;
  17. int secondDay;
  18.  
  19. cout << "Enter first dates month ";
  20. cin >> month;
  21.  
  22. cout << "Enter second dates month ";
  23. cin >> secondMonth;
  24.  
  25. cout << "Enter the first dates day ";
  26. cin >> day;
  27.  
  28. cout << "Enter the second dates day ";
  29. cin >> secondDay;
  30.  
  31. cout << "Enter the first dates year ";
  32. cin >> year;
  33.  
  34. cout << "Enter the second dates year ";
  35. cin >> secondYear;
  36.  
  37. if (month >= 10 && day >= 15 && year >= 1582)
  38.  
  39. cout << "The date you entered is invalid";
  40.  
  41. else
  42. DayCalculation ( month, day, year, secondMonth, secondDay,secondYear);
  43.  
  44. return 0;
  45. }
  46.  
  47. int DayCalculation ( int month, int day, int year, int month2, int day2, int year2)
  48.  
  49. {
  50. int result1 = 0;
  51. int result2;
  52. int result3;
  53.  
  54. long JulianDayNumber;
  55.  
  56. if (month == 1 || month == 2 )
  57.  
  58. {
  59. year--;
  60. month = month +12;
  61. }
  62.  
  63. result1 = 2- year/100+year / 400; // test each one to make sure the right number.
  64. result2 = int(365.25 * year);
  65. result3 = int(30.6001 * (month + 1));
  66.  
  67. JulianDayNumber = result1 + result2 + result3 + day + 1720994.5;
  68.  
  69. cout << JulianDayNumber << endl;
  70.  
  71. return 0;
  72.  
  73. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 35
Reputation: serfurj is an unknown quantity at this point 
Solved Threads: 2
serfurj's Avatar
serfurj serfurj is offline Offline
Light Poster

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

 
0
  #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:
  1. gcc -o dates dates.cpp
  2. dates.cpp: In function `int DayCalculation(int, int, int, int, int, int)':
  3. dates.cpp:67: warning: converting to `long int' from `double'
  4. /tmp/ccLb60he.o(.text+0x1b): In function `main':
  5. : undefined reference to `std::cout'
  6. /tmp/ccLb60he.o(.text+0x20): In function `main':
  7. : 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*)'
  8. /tmp/ccLb60he.o(.text+0x2e): In function `main':
  9. : undefined reference to `std::cin'
  10. /tmp/ccLb60he.o(.text+0x33): In function `main':
  11. : undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
  12. /tmp/ccLb60he.o(.text+0x42): In function `main':
  13. : undefined reference to `std::cout'
  14. /tmp/ccLb60he.o(.text+0x47): In function `main':
  15. : 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*)'
  16. /tmp/ccLb60he.o(.text+0x55): In function `main':
  17. : undefined reference to `std::cin'
  18. /tmp/ccLb60he.o(.text+0x5a): In function `main':
  19. : undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
  20. /tmp/ccLb60he.o(.text+0x69): In function `main':
  21. : undefined reference to `std::cout'
  22. /tmp/ccLb60he.o(.text+0x6e): In function `main':
  23. : undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
  24.  
  25. ......
  26.  
  27. Compilation exited abnormally with code 1 at Wed Dec 8 18:28:49
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 13
Reputation: britt_boy is an unknown quantity at this point 
Solved Threads: 1
britt_boy britt_boy is offline Offline
Newbie Poster

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

 
0
  #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 Quick reply to this message  
Join Date: Dec 2004
Posts: 35
Reputation: serfurj is an unknown quantity at this point 
Solved Threads: 2
serfurj's Avatar
serfurj serfurj is offline Offline
Light Poster

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

 
0
  #4
Dec 9th, 2004
no wonder. i'm using gcc.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
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]

 
0
  #5
Dec 14th, 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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 3234 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC