472,958 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Help with printing a calendar

hi i have this code to print out a calendar based on the year and month entered by user!!!!!
but im getting only the heading information ???can someone take a look at it and tell me whats wrong??TANX
my code so far is::

Full code removed per Posting Guidelines
Nov 17 '07 #1
20 5327
i need to write a program that prints the 12 months calandar given the weakday which should be the 1st of January for the years of 2001 and 2004( a leap year)!!! i know the test for leap year and i have written the FUN to determine the number of the days of months.
i just dont know how to print the calandar like
S M T W TH F SU
1 2 3 4 5 6
7 8 9 10 11 12 13
and so on....and the the of the next month should follow the end of previous month

... im sure i have to use the reference variables but im not sure how??
can you guys give me any ideas?
TANX
Nov 26 '07 #2
Ganon11
3,652 Expert 2GB
It should just be a matter of deciding how many days each month has, and then printing them in alignment (check out the setw() function in the iomanip header file for this). The first half is a mixture of simple logic and constants, the second half is experiment and 'making it look pretty'.
Nov 26 '07 #3
It should just be a matter of deciding how many days each month has, and then printing them in alignment (check out the setw() function in the iomanip header file for this). The first half is a mixture of simple logic and constants, the second half is experiment and 'making it look pretty'.
i know how many days esch month has. i dont know hoe to put the first day of January on the day of the week that user chooses?
like when a user inputes 2 (when Sunday is 1 and saturday is 7) the 1st day of january should be on monday!!!!!any ideas?
Nov 26 '07 #4
I think your main( ) needs changes. You need to assign the functions to variables when you are returning values from those functions. Also the code to generate the calendar needs to be appropriately changed. (Like the half written code inside the comment needs to be refined and continued...)
Nov 26 '07 #5
Ganon11
3,652 Expert 2GB
Again, this is a matter of experiment to make it look 'good'. My solution would be to simply print a certain number of spaces until you got under the 'M' spot, and then beginning to print.
Nov 26 '07 #6
sicarie
4,677 Expert Mod 4TB
Alenik1989-

Please do not double post - confine yourself to a single thread for each question you have.

Thanks
Nov 26 '07 #7
actually i didnt write the end of this code (my friend wrote it) where the code is

Full code removed per Posting Guidelines

can anyone please tell me whats the rule of this FUN, i mean whats is the daysofweek ? and what should i do with it?
Nov 27 '07 #8
sicarie
4,677 Expert Mod 4TB
Try stepping through the code line by line. Pass it a value that you think would make sense, and see where the logic takes you. Then pass it a value that you think would not make sense and see where the logic takes you.

As this is your friends code, I'm removing it from your post (due to our Posting Full Code rule in the Posting Guidelines, but if you come across a specific part you don't understand, post that part and your question, as well as the values you put in, what you got back, and why it doesn't make sense to you.
Nov 27 '07 #9
i just need a loop to print out the numbers from function in lines that in each line there will be 7 numbers!!!!!

like
1 2 3 4 5 6 7
8 9 10 11 12 13 14
i got the FUNC to determine the number of days ina month so
Expand|Select|Wrap|Line Numbers
  1. int i=1,j=1
  2. while( i<=FUNC)
  3. {
  4. while( j<=7)
  5. {
  6. if(i<=FUNC)
  7. {
  8. cout<<"   "<<i;
  9. i++
  10. j++
  11. }
  12. else
  13. break;
  14. }
  15. cout<<endl;
  16. j=1
  17. }
  18.  
just wanna know is this loop gonna work??? if not any idea how to write it???!!
please i need ASAP!! TANX
Nov 30 '07 #10
sicarie
4,677 Expert Mod 4TB
just wanna know is this loop gonna work???
I have no idea. Did you compile it?
Nov 30 '07 #11
I have no idea. Did you compile it?
yeh i got it!!!!tanx
Nov 30 '07 #12
i rewrote the code (myself) and now my code is like
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std;
  4. //_____________________Prototypes
  5. int leaptest(int);
  6. int daysofmonth(int,int);
  7. void printcalandar(int,int);
  8. int main()
  9. {
  10. int year,month=1;
  11. cin>>year;
  12. leaptest(year);//leapyearcheck
  13. while (month<=12)
  14. {
  15. daysofmonth(month,year);//# of days in a month
  16. printcalandar (month,year);//printing the calandar
  17. month++;
  18. }
  19. return 0;
  20. }
  21. int leaptest (int year)
  22. {
  23. if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
  24.   return 1; /* leap */
  25.  else
  26.   return 0; /* no leap */
  27. }
  28. int daysofmonth (int month,int year)
  29. {
  30. int days;
  31. int month2;
  32. month2 = month + 11;
  33. month2 = month2 * 7;
  34. month2 = month2 % 12;
  35. if (month2 < 7)
  36.   days = 31;
  37. else if (month==2)
  38. {
  39. if(leaptest(year)==1)
  40.     days=29;
  41.     else
  42.     days=28;
  43. }
  44. else
  45. days=30;
  46. return days;
  47. }
  48. void printcalandar(int month,int year)
  49. {
  50. int i=1,j=1;
  51. while(i<=daysofmonth(month,year))
  52. {
  53.     while(j<=7)
  54.     {
  55.         if(i<=daysofmonth(month,year))
  56.         {
  57.         cout<<setw(4)<<i;
  58.                   i++;
  59.         j++;
  60.         }
  61.         else 
  62.         break;
  63. }
  64. cout<<endl;
  65. if(i<=daysofmonth(month,year))
  66. j=1;
  67. else
  68. break;
  69. }
  70. cout<<"I="<<i<<"   j="<<j<<endl;
  71. }
this code will print 12 group month's calandar right.
but i want it to be like ...when each month ends the next month starts on the dayof the week that follows the last day of the preceding month!!!
like when january 31 is Monday then February 1st has to be on Thuesday.
Any ideas how??
i need it today pleasssssssssseeee!!!!
TANX
Nov 30 '07 #13
sicarie
4,677 Expert Mod 4TB
I'd create a variable, say 'dayOfWeekYesterday' and store it in there.
Nov 30 '07 #14
I'd create a variable, say 'dayOfWeekYesterday' and store it in there.
im new to programming, so can you be a little more specific?please?
where do i put the variable and how i make the loop to see it?
Dec 1 '07 #15
sicarie
4,677 Expert Mod 4TB
im new to programming, so can you be a little more specific?please?
where do i put the variable and how i make the loop to see it?
I would read up on rules of scope to decide where you should put that variable, but I'd recommend: your program. If you declare it outside your loop, your loop can see it. If you declare it inside your loop, your loop can see it, but every time the loop starts over, it will have an undefined value that you will need to reset.
Dec 1 '07 #16
I would read up on rules of scope to decide where you should put that variable, but I'd recommend: your program. If you declare it outside your loop, your loop can see it. If you declare it inside your loop, your loop can see it, but every time the loop starts over, it will have an undefined value that you will need to reset.
SORRY, but i still dont get it?
what is that variable suppose to do?
please i just have this pronblem with my calandar!!!
(i feel so stupid right now!!!!)
Dec 1 '07 #17
sicarie
4,677 Expert Mod 4TB
SORRY, but i still dont get it?
what is that variable suppose to do?
please i just have this pronblem with my calandar!!!
(i feel so stupid right now!!!!)
The variable holds the day of the week that the month ended with (as this is what you asked just a few posts ago...). Then you initialize the new month with the day after the one held in the variable.
Dec 1 '07 #18
The variable holds the day of the week that the month ended with (as this is what you asked just a few posts ago...). Then you initialize the new month with the day after the one held in the variable.
okay i knew that part but in order to give the variable the day of the week that the month ended with i have to put it the void printcalandar(month,year) function and before the final break right?
so after the function ends the memory location of all variables including this one will dialocated right?
so how a im suppose to initialize the new month with the day after the on in the variobale? (i know i have to add i to that variable but it should be in the functon as well)
Dec 1 '07 #19
sicarie
4,677 Expert Mod 4TB
okay i knew that part but in order to give the variable the day of the week that the month ended with i have to put it the void printcalandar(month,year) function and before the final break right?
so after the function ends the memory location of all variables including this one will dialocated right?
so how a im suppose to initialize the new month with the day after the on in the variobale? (i know i have to add i to that variable but it should be in the functon as well)
So printcalendar() only prints a month?

As it is declared a void, you aren't currently returning anything. You could return the current day of week, and then pass it back to that function.
Dec 1 '07 #20
So printcalendar() only prints a month?

As it is declared a void, you aren't currently returning anything. You could return the current day of week, and then pass it back to that function.
yeh printcalandar is a void function that i have putted in a while loop in main function to just print the 12 months using the # days in month.
Expand|Select|Wrap|Line Numbers
  1. while (month<=12)
  2. {
  3. daysofmonth(month,year);
  4. printcalandar (month,year);
  5. month++;
  6. }
but i cant return a value in void function can i?
you mean i have to change it to a returning value function?
Dec 1 '07 #21

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

Similar topics

10
by: Mario | last post by:
Hello all, I'm trying hard to make possible to print some simple text from python to the default printer using wxPython, after days of internet searches I found this page:...
0
by: Nigel | last post by:
I successfully create a .NET Component (Visual Basic .NET) that would print, unfortunately when used within a web browser it appears that .NET security doesn't allow you to run code that interacts...
0
by: Parthiv Joshi | last post by:
I want to make a week view calendar control just as month view calendar control given in .NET...Do anyone know how to make it..and if anybody has the source code..kindly post it...I want to learn...
2
by: TristaSD | last post by:
Hi, Here's a link to a simple php-based system I'm working on. Go ahead and play nice, nothing is validated :) http://www.basementflooded.com/reserv Currently, a calendar date is...
2
by: Kevin | last post by:
In my VB2005 Windows Forms program I want to be able to click a button and have my Dot Matrix printer print one 15/16 x 3 1/2 address label from continuous forms. I'm trying to use a...
0
by: hugo | last post by:
I need urgent help with this program: Using C, write a calendar progam so that the user provides only a year. The program should print a calendar for the given year to the file calendar.dat. The...
1
by: Marc | last post by:
Hi, I am setting up a orint function that prints the screen area. It is all working except my screen area spans two print pages hwne viewed using a print preview dialogue . I am trying to fnd a...
1
by: markclinn | last post by:
I am trying to use the calander control to pick a date and retrieve information from a database. When a date is clicked on, the page re-loads, with the selected date, gets the informatino from the...
0
by: rafiki31 | last post by:
I have been hitting walls trying to find the right way to print from a web application. Here is the thing, im implementing a webapplication for a kiosk. The kiosk has its own card printer. When i...
7
by: William (Tamarside) | last post by:
Please, if you have the time and knowledge to help me I'd truly appreciate it! I need to build a calendar page that displays available/unavailable info from a DB and colour a cell according to...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.