![]() |
|
#1
|
|||
|
|||
PrintCalendar Program [HELP PLEASE!!!]This program creat a calendar for a year
The program reads the year from the keyboard. It then calculates which day of the week (SUN, MON....SAT) is the first day of the year and prints the calendar for that year. After printing the year, it should ask id the user wants to continue. If the answer is yes, it will print the calendar for another year until the user is done. CPP / C++ / C Code:
The program print out many garbage which is not expected. I have struggled it for a long time already, but I cannot firgure out the problem. I am using Dev-C++ compiler 2nd question: Why the compiler don't allow me to use this statment in this program :: CPP / C++ / C Code:
I cannot see the result if I don't use this statment. Please help me...... |
|
#2
|
|||
|
|||
Re: PrintCalendar Program [HELP PLEASE!!!]First, you need a break after every case in a switch statement, or execution will "fall through" to the next case:
CPP / C++ / C Code:
What else do you mean by "garbage"? What was the expected output, and what was the actual output? The system() statement is in stdlib.h. However, use getchar() instead as it is much more portable, and faster. |
|
#3
|
|||
|
|||
Re: PrintCalendar Program [HELP PLEASE!!!]How can I use getchar()??
|
|
#4
|
||||
|
||||
Re: PrintCalendar Program [HELP PLEASE!!!]What book are you using? Doesn't it explain getchar()?
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#5
|
|||
|
|||
Re: PrintCalendar Program [HELP PLEASE!!!]Quote:
He may have meant putchar( '\n' ) instead of printf( "\n" ); The former is quicker, but not, IMHO more portable. ============================================= There are a few other things I can see, although the list is not necessarily exhaustive. 1.) First your week appears to have only six days in it, if you start counting from 1 CPP / C++ / C Code:
2.) Since the two printf's are part of the same compound statement, you need braces round them. CPP / C++ / C Code:
3.) I may be missing something, but why do you call printMonth twice, when you are going round the loop eleven times. CPP / C++ / C Code:
If you want to get two months on the same row I fear you may have a fair bit of rewriting to do. For example, Instead of CPP / C++ / C Code:
Similarly you would need to get the first (and subsequent) weeks in Jan/Feb or Mar/April onto the same line. You would also need to take account of the fact that Feb might only have four lines in it, but January might have six lines in it. Last edited by LuciWiz : 18-Nov-2006 at 13:58.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#6
|
|||
|
|||
Re: PrintCalendar Program [HELP PLEASE!!!]Actually, if you only want to display the calendar on the screen, rather than print it out, and you want to get two months on the same, you could simplify things a little bit if you could find a function to move the cursor to the right of January before printing the lines for February. I'm sure there would be such a function buried away amongst your library functions somewhere (although it is not part of the standard C library).
|
Recent GIDBlog
Stupid Management Policies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| BOOKEEPING program, HELP!! | yabud | C Programming Language | 10 | 17-Nov-2006 04:48 |
| Pipeline freeze simulation | darklightred | C++ Forum | 6 | 27-Jul-2006 20:37 |
| How to read particular memory location ? | realnapster | C Programming Language | 10 | 10-May-2006 10:11 |
| Type casts ? | kai85 | C++ Forum | 12 | 23-Jun-2005 13:04 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 08:10 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The