Calendar Program in C

write a program in C

Page 1 of 1

4 Replies - 8763 Views - Last Post: 22 October 2010 - 05:34 AM Rate Topic: -----

#1 Hitch911  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-October 10

Calendar Program in C

Posted 22 October 2010 - 04:56 AM

Write a program to print a one-month calendar or one-year calendar.
Assume your program is named as cal.
1. Run ‘cal 2010’ will print the year calendar of 2010.
2. Run ‘cal 2010 10’ or ‘cal 2010 Oct’ will print month calendar of Octobor 2010, which a number or a 3-character month name with the first capital character is used.

I need some help please, I already started to write it but i cannot finish. Could you please tell me wht should i do??:(:(:(

HERE IS MY PROGRAM!!!

#include<stdio.h>
#include<stdlib.h>

int main(int argc,char *argv[])
{
int b[31];
int month[12];

scanf("%d%d%d%d",&b[0], &b[1], &b[2], &b[3]);
scanf("%d%d%d%d",&b[4], &b[5], &b[6], &b[7]); 
scanf("%d%d%d%d",&b[8], &b[9], &b[10], &b[11]); 
scanf("%d%d%d%d",&b[12], &b[13], &b[14], &b[15]);
scanf("%d%d%d%d",&b[16], &b[17], &b[18], &b[19]);
scanf("%d%d%d%d",&b[21], &b[22], &b[23], &b[24]);
scanf("%d%d%d%d%d%d",&b[25], &b[26], &b[27], &b[29], &b[30], &b[31]);
printf("%5d%5d%5d%%5d", b[0], b[1], b[2], b[3], b[4], b[5]);
printf("%5d%5d%5d%%5d", b[0], b[1], b[2], b[3], b[4], b[5]);
printf("%5d%5d%5d%%5d", b[0], b[1], b[2], b[3], b[4], b[5]);
printf("%5d%5d%5d%%5d", b[0], b[1], b[2], b[3], b[4], b[5]);
	
	printf("January; February; March; April; May; June; July; August; September; October; November; December ");

 if (month == 12)
   printf("December\n");
 else if (month == 3)
   printf("November\n");	
 else if (month == 31)
   printf("October\n");
 else if (month == 30)
   printf("September\n");
 else if (month == 31)
   printf("August\n");
 else if (month == 31)
   printf("July\n");
 else if (month == 30)
   printf("June\n");
 else if (month == 31)
   printf("May\n");
 else if (month == 30)
   printf("April\n");
 else if (month == 31)
   printf("March\n");
 else if (month == 28)
   printf("February\n");              
 else if (month == 31)
   printf("January\n");	
   
   
    switch (month)
	
{
	case 12:
		numdays += 30;
		break;
	case 11:
		numdays += 31;
		break;
	case 10:
		numdays += 30;
		break;
	case 9:
		numdays += 31;
		break;
	case 8:
		numdays += 31;
		break;
	case 7:
		numdays += 30;
		break;
	case 6:
		numdays += 31;
		break;
	case 5:
		numdays += 30;
		break;
	case 4:
		numdays += 31;
		break;
	case 3:
		if ((!(year % 4) && (year % 100)) || ! (year % 400))
			numdays += 29;
		else numdays += 28;
		break;
	case 2:
		numdays += 31;
		break;
    

}
	
	
	system("pause");

}
	



switch (Day)
{
	case 6:
		printf("Saturday");
break;
	case 5:
		printf("Friday");
break;
	case 4:
		printf("Thursday");
break;
	case 3:
		printf("Wedensday");
break;
	case 2:
		printf("Tuesday");
break;
	case 1:
		printf("Monday");
break;
	case 0:
		printf("Sunday");
break;
}
	
    return(0);
}
*/


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 22 October 2010 - 05:02 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Calendar Program in C

#2 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: Calendar Program in C

Posted 22 October 2010 - 05:02 AM

Use the code tags! :code:
Was This Post Helpful? 0
  • +
  • -

#3 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Calendar Program in C

Posted 22 October 2010 - 05:09 AM

What you should do is address all these complaints from the compiler

dic.c: In function ‘main’:
dic.c:16: warning: too many arguments for format
dic.c:17: warning: too many arguments for format
dic.c:18: warning: too many arguments for format
dic.c:19: warning: too many arguments for format
dic.c:23: warning: comparison between pointer and integer
dic.c:25: warning: comparison between pointer and integer
dic.c:27: warning: comparison between pointer and integer
dic.c:29: warning: comparison between pointer and integer
dic.c:31: warning: comparison between pointer and integer
dic.c:33: warning: comparison between pointer and integer
dic.c:35: warning: comparison between pointer and integer
dic.c:37: warning: comparison between pointer and integer
dic.c:39: warning: comparison between pointer and integer
dic.c:41: warning: comparison between pointer and integer
dic.c:43: warning: comparison between pointer and integer
dic.c:45: warning: comparison between pointer and integer
dic.c:49: error: switch quantity not an integer
dic.c:53: error: ‘numdays’ undeclared (first use in this function)
dic.c:53: error: (Each undeclared identifier is reported only once
dic.c:53: error: for each function it appears in.)
dic.c:80: error: ‘year’ undeclared (first use in this function)
dic.c:94: warning: control reaches end of non-void function
dic.c: At top level:
dic.c:99: error: expected identifier or ‘(’ before ‘switch’
dic.c:124: error: expected identifier or ‘(’ before ‘return’
dic.c:125: error: expected identifier or ‘(’ before ‘}’ token
dic.c:126: error: expected identifier or ‘(’ before ‘/’ token



Showing us code that doesn't even compile without telling us the compile errors you are getting is a very good way to get your posts ignored.
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5820
  • View blog
  • Posts: 12,671
  • Joined: 16-October 07

Re: Calendar Program in C

Posted 22 October 2010 - 05:23 AM

What you shouldn't do is ask the user for 32 points of data. That will only piss them off and drive you nuts working on the thing.

User input is year and month.

Your program most know the number of days in a month. It must know what the first day of any given month is. And, ideally, it should know if it's a leap your or now ( for February ). The program should know these things, not the user.

Use functions, arrays, and loops.

Functions you'll want to write might look like:
int getDaysInMonth(int year, int month);
int firstDayOfMonth(int year, int month);
const char *getMonthName(unsigned int month);
void showCalMonth(int year, int month);
void showCalYear(int year);


Was This Post Helpful? 0
  • +
  • -

#5 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Calendar Program in C

Posted 22 October 2010 - 05:34 AM

View Postbaavgai, on 22 October 2010 - 09:23 PM, said:

User input is year and month.



@Hitch911
And that input must be collected at the command line when launching the program.
There should not be any user input collected during the program execution at all - read the requirements you quoted at the top of your posting.
If you have even a single scanf() in your code you have failed to read and understand the requirements. Having 32 is a major fail.
Remove every single one of them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1