Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 8, 2007, 05:15 PM   #1
andrewface
macrumors regular
 
Join Date: May 2006
i need some more C help

i need to write a program that asks the user for the number of days of the week and the starting day of the month and i need it to print out a months calendar

any advice?

edit: heres what ive got so far

#include <stdio.h>

int main() {
// declare variables
int numberofdays, startday;
char nameofmonth[10];
//Explains program and asks for the name of the month, and week start number
printf("This program creates a calendar for one month\nPlease enter the name of the month:");
scanf("%s", nameofmonth);
printf("Please enter the number of days in the month:");
scanf("%d", &numberofdays);
printf("Please enter the day of the week that the month starts; starting with Sunday 1-7:");
scanf("%d", &startday);
printf("%17s\nSun Mon Tue Wed Thu Fri Sat\n", nameofmonth);
printf("1 2 3 4 5 6 7"); //lost here this doesnt work...

return 0;

}
__________________
2011 MBP i7 4Gb Ram
andrewface is offline   0 Reply With Quote
Old Feb 8, 2007, 05:54 PM   #2
bousozoku
Moderator emeritus
 
Join Date: Jun 2002
Location: Gone but not forgotten.
You'd probably want to use the tab 't character to separate things to make them a bit neater.

Also, you'll likely want to use a calculation to figure out how many weeks to loop. You know how to use for loops, right?

The modulo operator % should come in handy, too.
bousozoku is offline   0 Reply With Quote
Old Feb 8, 2007, 05:56 PM   #3
andrewface
Thread Starter
macrumors regular
 
Join Date: May 2006
Quote:
Originally Posted by bousozoku View Post
You'd probably want to use the tab 't character to separate things to make them a bit neater.

Also, you'll likely want to use a calculation to figure out how many weeks to loop. You know how to use for loops, right?

The modulo operator % should come in handy, too.
yes i have no idea what calculations to use in the for loops thats the thing
__________________
2011 MBP i7 4Gb Ram
andrewface is offline   0 Reply With Quote
Old Feb 8, 2007, 06:26 PM   #4
scan
macrumors 6502
 
Join Date: Oct 2005
I don't understand what your program is suppose to do. Could you explain it a little bit clearer?

All your program does is takes the input. Not to be rude but a monkey could have written that code. You could at least try to solve the problem yourself instead of asking people to do your homework.
scan is offline   0 Reply With Quote
Old Feb 8, 2007, 06:28 PM   #5
bousozoku
Moderator emeritus
 
Join Date: Jun 2002
Location: Gone but not forgotten.
Quote:
Originally Posted by andrewface View Post
yes i have no idea what calculations to use in the for loops thats the thing
Perhaps, then, you should sit down with pencil and paper and figure out how you would do it step-by-step. Once you figure out how that works, you can translate it to code.
bousozoku is offline   0 Reply With Quote
Old Feb 8, 2007, 06:35 PM   #6
andrewface
Thread Starter
macrumors regular
 
Join Date: May 2006
Quote:
Originally Posted by scan View Post
I don't understand what your program is suppose to do. Could you explain it a little bit clearer?

All your program does is takes the input. Not to be rude but a monkey could have written that code. You could at least try to solve the problem yourself instead of asking people to do your homework.
im one dumb monkey then
__________________
2011 MBP i7 4Gb Ram
andrewface is offline   0 Reply With Quote
Old Feb 8, 2007, 06:39 PM   #7
toddburch
macrumors 6502a
 
Join Date: Dec 2006
Location: Katy, Texas
Send a message via AIM to toddburch Send a message via MSN to toddburch
Andrew, some free advice...

You have to be able to communicate your thoughts onto paper (or in type) to solve "math" type problems (aka word problems). Once you can do it by math, you can then write code that implements the math.

Fumbling with code before you have an action plan is a waste of time. Take the time to write out what it is you need to do, as a series of steps, then approach the problem from a coding standpoint.

- get the month (this goes on the top of the report)
- get the # of days in the month
- get the first day of the month.

You have that so far.

The first day of the month will be your trigger to starting printing with "1" when you get to it in the first loop. For instance, if the day entered was 4, then for the first 3 positions in the row for the first week, you'll print blanks. Once you hit your target day, then you can start clicking off 1, 2, 3, and so on.

You need two loops - an outer loop and an inner loop.

The outer loop will print the line you build in the inner loop and manage the CRLF to create make the report look like a table.

The inner loop will build the print line with

1) either blanks and numbers (for the first week), or
2) all numbers (for the first, middle or last weeks) or
3) numbers and blanks (for the last week).

Your trigger to quit the loops is when you've accounted for "numberofdays" days.

So, keep coding with this in mind and see what you come up with.

Todd
toddburch is offline   0 Reply With Quote
Old Feb 8, 2007, 06:45 PM   #8
andrewface
Thread Starter
macrumors regular
 
Join Date: May 2006
Quote:
Originally Posted by toddburch View Post
Andrew, some free advice...

You have to be able to communicate your thoughts onto paper (or in type) to solve "math" type problems (aka word problems). Once you can do it by math, you can then write code that implements the math.

Fumbling with code before you have an action plan is a waste of time. Take the time to write out what it is you need to do, as a series of steps, then approach the problem from a coding standpoint.

- get the month (this goes on the top of the report)
- get the # of days in the month
- get the first day of the month.

You have that so far.

The first day of the month will be your trigger to starting printing with "1" when you get to it in the first loop. For instance, if the day entered was 4, then for the first 3 positions in the row for the first week, you'll print blanks. Once you hit your target day, then you can start clicking off 1, 2, 3, and so on.

You need two loops - an outer loop and an inner loop.

The outer loop will print the line you build in the inner loop and manage the CRLF to create make the report look like a table.

The inner loop will build the print line with

1) either blanks and numbers (for the first week), or
2) all numbers (for the first, middle or last weeks) or
3) numbers and blanks (for the last week).

Your trigger to quit the loops is when you've accounted for "numberofdays" days.

So, keep coding with this in mind and see what you come up with.

Todd
thanks alot ima keep going at it
__________________
2011 MBP i7 4Gb Ram
andrewface is offline   0 Reply With Quote
Old Feb 8, 2007, 07:03 PM   #9
scan
macrumors 6502
 
Join Date: Oct 2005
Quote:
Originally Posted by andrewface View Post
im one dumb monkey then
my comment was not to insult you. It was actually suppose to help you. I know that you're just starting out but asking for people to do your homework is not going to make you a better programmer. You need to practice get yourself thinking like a programmer. You learn from experience how to tackle types of problems.
scan is offline   0 Reply With Quote
Old Feb 8, 2007, 11:05 PM   #10
toddburch
macrumors 6502a
 
Join Date: Dec 2006
Location: Katy, Texas
Send a message via AIM to toddburch Send a message via MSN to toddburch
Just an FYI - I worked it out. So, when you're ready with your next hurdle, holler.

Code:
[Session started at 2007-02-08 23:01:19 -0600.]
This program creates a calendar for one month
Please enter the name of the month: December
Please enter the number of days in the month: 31
Please enter the day of the week that the month starts; starting with Sunday 1-7: 7


	December
	Sun 	Mon 	Tue 	Wed 	Thu 	Fri 	Sat
	    	    	    	    	    	    	  1 
	  2 	  3 	  4 	  5 	  6 	  7 	  8 
	  9 	 10 	 11 	 12 	 13 	 14 	 15 
	 16 	 17 	 18 	 19 	 20 	 21 	 22 
	 23 	 24 	 25 	 26 	 27 	 28 	 29 
	 30 	 31 	    	    	    	    	    

Calendar has exited with status 0.
and...

Code:
[Session started at 2007-02-08 23:03:13 -0600.]
This program creates a calendar for one month
Please enter the name of the month: February
Please enter the number of days in the month: 28
Please enter the day of the week that the month starts; starting with Sunday 1-7: 1


	February
	Sun 	Mon 	Tue 	Wed 	Thu 	Fri 	Sat
	  1 	  2 	  3 	  4 	  5 	  6 	  7 
	  8 	  9 	 10 	 11 	 12 	 13 	 14 
	 15 	 16 	 17 	 18 	 19 	 20 	 21 
	 22 	 23 	 24 	 25 	 26 	 27 	 28 

Calendar has exited with status 0.
Todd
toddburch is offline   0 Reply With Quote
Old Feb 9, 2007, 12:01 AM   #11
bousozoku
Moderator emeritus
 
Join Date: Jun 2002
Location: Gone but not forgotten.
Quote:
Originally Posted by toddburch View Post
Just an FYI - I worked it out. So, when you're ready with your next hurdle, holler.
...
Todd
Don't you think you've already helped too much? He's supposed to be paying attention in class and reading his books and learning to solve problems on his own, as well as code the solutions.

Maybe, you should consider waiting until he's got it running fairly well.
bousozoku is offline   0 Reply With Quote
Old Feb 9, 2007, 12:27 AM   #12
toddburch
macrumors 6502a
 
Join Date: Dec 2006
Location: Katy, Texas
Send a message via AIM to toddburch Send a message via MSN to toddburch
Quote:
Originally Posted by bousozoku View Post
Don't you think you've already helped too much? He's supposed to be paying attention in class and reading his books and learning to solve problems on his own, as well as code the solutions.
No I don't think I've helped too much, and neither you or I know that he is or is not doing what you say he should be doing. The guy is obviously struggling with basics here. I simply tried to point his head in the right direction.

Quote:
Originally Posted by bousozoku View Post
Maybe, you should consider waiting until he's got it running fairly well.
Am. I don't categorize showing the output as any kind of give-away. The earlier prose was to get him to think about the overall objectives and thinking (and hopefully heading) in the right direction.

Todd
toddburch is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 04:21 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC