Note: in both arrays the first position is empty on purpose, we want to use 1 to 12 to keep things simple. The first function inputyear is used to get the user input. We ask the user to input a year. Note: that there is no input checking or error handling is performed to keep things simple.
The next function determinedaycode is used to get the day number of the first day in that year, so we can print the date on the correct position. So it is only used for output purposes. The next function determineleapyear is used to determine if input of the user is a leap year. If so, the number if days in February is changed to The last function calendar is used to print each month onto the screen.
The first for loop is used to loop through all months. We then use the daycode to position the prompt under the right weekday. Then we print all the dates for one month. The last thing we do is to set the position of the prompt on the right weekday.
Can anyone help me? On my last post the months February and April should been a few spaces foward like the week day. Am trying to develop a program to output the date on requesting for a 30 days leave and when the leave will end. But it is not working out. The floats are causing it. If the decimals are removed it works fine and the code works fine as is compiled with MinGW.
I want to implement in c where the year,month and date are entered in individual textboxs by the user and the corresponding day has to be displayed in another textbox. Can someone help me with the codes? So for example for this is 2, so the printing is started on Tuesday. In the year this first day is on Sunday, so the output of determinedaycode will be 0 zero. I want a program for my project that will count the number of days by inputting two distinct dates. This site is really good for first time users I mean start users.
The way it explains and codes is very basic and easy to understand. I am making a signup page and i want to add the calender to that for the DOB column, but i want to print an error if the age preceeds 18 year from now.. All Rights Reserved. Home About. Dave Rager Dave Rager 7, 2 2 gold badges 29 29 silver badges 51 51 bronze badges. Bernd Elkemann Bernd Elkemann Dinesh Verma Dinesh Verma 3 3 silver badges 8 8 bronze badges.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast GitHub Copilot can write code for you. We put it to the test. Privacy is an afterthought in the software lifecycle. That needs to change. Featured on Meta. New VP of Community, plus two more community managers.
Deprecating our mobile views. Congratulations BalusC for reaching a million reputation! Visit chat. Related Hot Network Questions. Question feed.
I think you need braces after the for First, think about how to print numbers arranged in a block of N numbers per line, like so: 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 This is done easily with a for loop with an if statement. Next, you'll have to figure out how to start at an arbitrary point in the line: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Given that you know what day of the week to start on, how would you begin counting from the first element of the first line?
How do I print blank spaces? This is really a terrible assignment, it just throws me in the water before I have learnt how to swim. And I'm drowning. This was my first Computer Science assignment, too! Seriously, though If not, keep posting, and the hints will probably get more explicit. Thanks a lot, how do I print out a blank spot?
I thought I could use an If statement to print a new line, as suggested in the tip. So the 7th day is the end of the line and a new line should start. However, how do print a blank spot? I use the For loop to keep counting the days up till the days of the months, then the loops ends. This is what I do understand. The 7th number saturday of a row is start of newline.
However, will an If statement be sufficicient and do the trick? Using truth and false values to start a newline? Is there a way to avoid that and keep it easier for me to understand? I think I can never complete this program with only the book King I have, and my instructor only tells what's written in the books in the same way, so that's no use either.
If i is a multiple of 7, you will have printed into 7 places either spaces or numbers on that line. Unless you literally want to know how to print out an empty space: printf " " ;. Not that it matters any more Like I said before, don't make it more difficult than it has to be. How would you do it if you were going to type a calendar out in notepad? You'd hit the spacebar a bunch of times. If you use your code, you either have to keep resetting i to 1 at the end of each week at which point you have to do further fenagling to get your loop to stop at the end of the month , or the line just keeps on going.
The modulus operator will give you a remainder of 0 whenever i is divisible by 7 if i is divisible by 7, then it has no remainder, right? If you use this, you have an easy test to know whenever you reach a number that is divisible by another number. This comes in handy because, looking at a calendar, Saturday isn't just the 7th day of the week. Starting from the first Sunday position, it's in the 7th, the 14th, the 21st It isn't strictly necessary for this assignment, but become friends with the modulus operator, you'll need it if you continue to program.
Thanks a lot. It looks very strange to me, but I have just started to learn the basics of C. So perhaps one day it won't look strange anymore. In the first row or line , it should jump to to the 3rd place when the user enters 3 for the firstday. X spot when firstday is X.
How to code this? I think this would be the easiest way to go, since you know how many balnks you need, and it only has to be done once. Let me know if you need any more on this. You are getting there, the first few programs can be the hardest.
Best of luck with it! However, I have no idea how the For loop should look like. I think I need to count down, so the loop is probably the opposite of the first loop. And when I got the loop, is it possible just to combine the 2 loops? My mind is not clear now The problem is that it should jump in firstday-1 times and then start in the first line of the loop and that loop should start with the firstday digit entered by the user.
This is the first step. I'm trying to make a one-month calendar in C. This code kind of works, but for some inputs the spacing is off. I don't quite know how to fix it. Also, if you have a way of making a one month calendar that involves less code than this, that would be great, since I have to regurgitate this on a test in about an hour. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 8 years, 5 months ago. Active 6 years ago. Viewed 12k times. Run in a debugger, step though the code line by line, while checking all your calculations and variables. I also recommend you do a layout on squared paper, when one square is one character. Makes it very easy to test different layouts and count number of spaces.
Add a comment. Active Oldest Votes. How was your test? Dave Rager Dave Rager 7, 2 2 gold badges 29 29 silver badges 51 51 bronze badges. Bernd Elkemann Bernd Elkemann Dinesh Verma Dinesh Verma 3 3 silver badges 8 8 bronze badges. Sign up or log in Sign up using Google.