944,150 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3716
  • C++ RSS
Dec 8th, 2004
0

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

Expand Post »
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:

C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jtxay is offline Offline
11 posts
since Dec 2004
Dec 8th, 2004
0

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

Quote 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:
C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 32
Solved Threads: 2
Light Poster
serfurj is offline Offline
35 posts
since Dec 2004
Dec 9th, 2004
0

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

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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
britt_boy is offline Offline
13 posts
since Dec 2004
Dec 9th, 2004
0

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

no wonder. i'm using gcc.
Reputation Points: 32
Solved Threads: 2
Light Poster
serfurj is offline Offline
35 posts
since Dec 2004
Dec 14th, 2004
0

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

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....
Reputation Points: 16
Solved Threads: 6
Posting Pro in Training
1o0oBhP is offline Offline
445 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: confused loops
Next Thread in C++ Forum Timeline: need help with this error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC