473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Calendar not working as plan

64
Hello, I am trying to write up a calendar with no luck. Well, I am trying to test "calcJanFirst", but when I type in the year and send it to calcJanFirst I alway get the same number. No matter what year I put in. I believe I am sending the value incorrectly to calcJanFirst. Can someone check what i'm doing wrong please. Thank you.

Expand|Select|Wrap|Line Numbers
  1. /* 
  2.     Print Calendar
  3.  
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8. //    Function Declarations 
  9. int  getYear      ( void );
  10. int  calcJanFirst ( int year );
  11. void printCalendar( int year, int JanFirst );
  12.  
  13. int  chooseDays   ( int year, int month );
  14. int  isLeap       ( int year );
  15.  
  16. void printHeader  ( int year, int month );
  17. int  printMonth   ( int firstDay, int days );
  18.  
  19. int main( void )
  20. {
  21. //    Local Declarations  
  22.     int year, month,firstday,JanFirst;
  23.  
  24. //    Statements
  25.     getYear();
  26.  
  27.  
  28.     //printMonth(2, 29); // starting date and ending dates
  29.      calcJanFirst(JanFirst);
  30.  
  31.  
  32.  
  33.     return 0;
  34. }
  35.  
  36.  
  37.  
  38. /* ======================================================= */
  39. /* This function prompts the user to enter a year: if it is 
  40.    within the range 1000 to 3000 it is considered a valid year;
  41.    otherwise, it prompts the user to enter another value, until 
  42.    it is valid.
  43.     PRE : nothing
  44.     POST: year is returned
  45. */
  46. int  getYear      (void)
  47. {
  48. //    Local Declarations
  49. int year;
  50. //    Statements 
  51.  
  52.     printf("Please enter a year between 1000 to 3000\n");
  53.     scanf("%d",&year);
  54.  
  55.     if(!(year >=1000) || !(year <=3000))
  56.     {
  57.          while(year<1000 || year>3000)
  58.          {
  59.                printf("Please enter a year between 1000 to 3000\n");
  60.                scanf("%d\n",&year); 
  61.          }
  62.  
  63.     }
  64.     return year;
  65. }
  66.  
  67. /* ======================================================= */
  68. /* This function determines the day of the week for 
  69.    January first: 0 - Sunday, 1 - Monday, ... 6 - Saturday.
  70.             - see formula at page 388
  71.     PRE : year 
  72.     POST: day of the week for Jan 1st returned
  73.  
  74. */
  75. int  calcJanFirst ( int year )
  76. {
  77.     int JanFirst;
  78.  
  79.     JanFirst = (((year - 1 ) * 365) + ((year - 1) % 4) - ((year - 1) % 100) + 
  80.     ((year - 1) %400)+1)%7;
  81.  
  82.     printf("testing calcJanFirst %d",JanFirst);
  83.      return JanFirst;
  84. }
  85.  
  86.  
Mar 1 '07 #1
1 1247
DeMan
1,806 1GB
1) I think you should save the resuklt of getYear (I'd use year rather than JanFirst....
2) I think you should pass this result to calcJanFirst

viz
Expand|Select|Wrap|Line Numbers
  1. int main (void) //if you like
  2. {
  3.   int year, month, JanFirst;  //etc
  4.   year = getYear();  /this is why we have the year variable I would assume
  5.   JanFirst = calcJanFirst(year);
  6.   printf("The year is %d and JanFirst is %d", year, JanFirast);
  7. }
  8.  
Mar 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Shelly | last post by:
Hi all I require a calendar control in .NET in Japanese. But how do I convert this into the year convention followed in Japan, as I understand that it is different from ours?? Please help me...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
8
by: Shyguy | last post by:
Is it possible to create a calendar that shows previous input data and also allows for input of new data?
6
by: Jeff S | last post by:
I would like recommendations for implementing a calendar in an ASP.NET web site. My plan is to store date and event information (e.g,, "Spring Sale") in a database, and when the page is requested,...
1
by: R.A.M. | last post by:
Hello, I need to implement popup calendar in ASP.NET application. I created a button opening popup calendar on 'master' page: <asp:Button ID="Calendar" runat="server" Text=Calendar"...
0
by: larry | last post by:
I am in the process of rewriting one of my first PHP scripts, an event calendar, and wanted to share the code that is the core of the new calendar. My current/previous calendar processed data...
4
by: gubbachchi | last post by:
Hi all, Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters...
6
by: sbettadpur | last post by:
hello everybody, i am using readymade popup calendar for my application, it's working fine. But i am facing some problem i.e. if i click on the calendar image it will open a calendar. below...
0
by: juanmorero | last post by:
When I attempt to create a call plan in the Calendar screen and I'm trying to drag the contact to the Calendar applet. After that, I tried to click on the hyperlink in the calendar applet so as to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.