In C programming. How do you build a calendar? I can't get the days to work right.
This is what I have so far
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int dow(int year, int month, int day)
{
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6,
2, 4};
year -= month < 3;
return (year + year/4 - year/100 + year/400 +
t[month-1] + day) % 7;
}
int main()
{
int year, month, day,daysM;
printf("Please input the year: ");
scanf("%d",&year);
char *months[]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int monthDay[]={31,28,31,30,31,30,31,31,30,31,30,31};
if (year==-1){
printf("Error, no year
specified\n");
return 1;
}
if (year < 1752) {
printf("Error, year is
earlier than 1752\n");
return 1;
}
if ((year + year/4 - year/100 + year/400 +
day) % 7)
{
monthDay[1]=29;
}
for (month=0; month<12; month++)
{
daysM=monthDay[month];
printf("\n%s
%d\n",months[month],year);
printf(" Sun Mon Tue Wed
Thu Fri Sat\n\n");
for(day=1;day<daysM;day++)
{
printf("%5d",day);
if (day>6)
{
printf("\n");
}
}
}
}
Check this program in C it will work fine for the calendar to work
/*This program prints a calendar for a year specified. The user enters a
year for the calendar and the programs automatically prints the calendar
in text format.
The codes are: day_code (0 = Sun, 1 = Mon, etc.)
leap_year (0 = no leap year, 1 = leap year) */
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
int get_day_code (int year);
int get_leap_year (int year);
void print_calendar (FILE *fout, int year, int day_code, int leap_year);
int get_year (void);
main()
{
int year, day_code, leap_year;
FILE *fout;
fout = fopen ("calendar.txt", "w");
year = get_year();
day_code = get_day_code (year);
leap_year = get_leap_year (year);
print_calendar(fout, year, day_code, leap_year);
printf("Open up \'calendar.txt\' to see your calendar...\n");
system("pause");
}
int get_year (void)
{
int year;
printf ("Enter a year: ");
scanf ("%d", &year);
return year;
}
int get_day_code (int year)
{
int day_code;
int x1, x2, x3;
x1 = (year - 1.)/ 4.0;
x2 = (year - 1.)/ 100.;
x3 = (year - 1.)/ 400.;
day_code = (year + x1 - x2 + x3) %7;
return day_code;
}
int get_leap_year (int year)
{
//if((year% 4) == 0 );
if(year% 4==0 && year%100 != 0 || year%400==0)
return TRUE;
else return FALSE;
}
void print_calendar (FILE *fout, int year, int day_code, int leap_year) //function header
{
int days_in_month, /* number of days in month currently
being printed */
day, /* counter for day of month */
month; /* month = 1 is Jan, month = 2 is Feb, etc. */
fprintf (fout," %d", year);
for ( month = 1; month <= 12; month++ ) {
switch ( month ) { /* print name and set days_in_month */
case 1:
fprintf(fout,"\n\nJanuary" );
days_in_month = 31;
break;
case 2:
fprintf(fout,"\n\nFebruary" );
days_in_month = leap_year ? 29 : 28;
break;
case 3:
fprintf(fout, "\n\nMarch" );
days_in_month = 31;
break;
case 4:
fprintf(fout,"\n\nApril" );
days_in_month = 30;
break;
case 5:
fprintf(fout,"\n\nMay" );
days_in_month = 31;
break;
case 6:
fprintf(fout,"\n\nJune" );
days_in_month = 30;
break;
case 7:
fprintf(fout,"\n\nJuly" );
days_in_month = 31;
break;
case 8:
fprintf(fout,"\n\nAugust" );
days_in_month = 31;
break;
case 9:
fprintf(fout,"\n\nSeptember" );
days_in_month = 30;
break;
case 10:
fprintf(fout,"\n\nOctober" );
days_in_month = 31;
break;
case 11:
fprintf(fout,"\n\nNovember" );
days_in_month = 30;
break;
case 12:
fprintf(fout,"\n\nDecember" );
days_in_month = 31;
break;
}
fprintf(fout,"\n\nSun Mon Tue Wed Thu Fri Sat\n" );
/* advance printer to correct position for first date */
for ( day = 1; day <= 1 + day_code * 5; day++ )
fprintf(fout," " );
/* print the dates for one month */
for ( day = 1; day <= days_in_month; day++ ) {
fprintf(fout,"%2d", day );
if ( ( day + day_code ) % 7 > 0 ) /* before Sat? */
/* move to next day in same week */
fprintf(fout," " );
else /* skip to next line to start with Sun */
fprintf(fout, "\n " );
}
/* set day_code for next month to begin */
day_code = ( day_code + days_in_month ) % 7;
}
}
In C programming. How do you build a calendar? I can't get the days to work...
Can someone fix my coding please it's a calendar some days are placed wrong. I just want the Main menu to display first and second option and four option to end the program properly. Please remove option number 3 Find the number of days between 2 selected dates and the code that belongs to this function. #include<stdio.h> void days(int,int,int,int,int,int); int month(int,int); int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31}; #define TRUE 1 #define FALSE 0 int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; char *months[]= { " ", "\n\n\nJanuary", "\n\n\nFebruary", "\n\n\nMarch", "\n\n\nApril",...
Create a calendar for the year 2019, for a particular month (of your choosing ), highlight a particular date (also your choosing) with an asterisk. Make sure the calendar displays the week, the days of the week and the year. Make sure the MSU Programming Class appears in the title of the Calendar. I will choose May 1st for the month and date. The code below is what I will be using. Please show where I can go to in...
Need help, i can't get a infinite loop to work, that terminates when a blank line is inputted for the firstName. note: C programing langauge and using microsoft visual studios . #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <math.h> #include <stdbool.h> int main() { //int arraySalaries[50]; int calculate_avg = 0; //int calculate_max; //int calculate_min; int salary[50]; //int length; //int average_salary; char firstName[50][50]; char lastName[50][50]; int i...
please rewrite or convert this C program into Assembly language and please make a notice of which function is which! #include <stdio.h> #include <stdlib.h> void printMonthYear(int mon,int year); void printDaysOfWeek(); void printDays(int mon,int year); int getFirstDayOfMonth(int mon, int year); int getNumOfDaysInMonth(int mon, int year); int main(void) { int mon=-1; int year= -1; printf("Month : "); fflush(stdout); scanf("%d",&mon); if(mon < 1|| mon > 12){ printf("Invalid month >.<!: %d ! Must be between 1 and 12\n",mon); return 1; } printf("Year...
Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs: 1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week: 0 Sunday 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday Your program should...
Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. The program prompts the user for two inputs: 1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week: ...
c++ please :)
First, ask the user to enter a year (4-digit) and what week day does this year starts with (String) For example, the year 2018 starts with the week day "Friday". In this case, the calendar should start from January 1 which is Friday, 2018 Your program should produce a formatted calendar for the specified year and there should be a blank line after each month. Moreover, the month and the year should be centered over each month....
Help with Python problem.
###################################### Q3 ############################### dowt = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat') # day-of-week-tuple, # year = 2020 cnt = 3 # 2020/1/1 is a Wednesday, so let us start a counting index of 3 for Wednesday, and keep adding one # m = 3 # this will be a variable to be looped through eventually. I use the convention of 0–11 for the twelve months # # As the cnt value changes, we want to...
I am writing a program that reads ten integers from standard input, and determines if they are going up or down or neither. Can I get some help? I have supplied what I have already. #include <stdio.h> #include <string.h> #include <stdlib.h> int isGoingUp(int [a]); int isGoingDown(int [b]); int main(void) { int array[10]; printf("Enter ten integers : "); for (int a = 0; a < 10; a++) scanf("%d", &array[a]); if (isGoingUp(array) == 1) printf("The values are going up\n"); else if (isGoingDown(array)...
I am told to find the median of random inputs using if statements in C #include <stdio.h> #include <stdlib.h> int main() { double a, b, c, d; scanf("%lf", &a); scanf("%lf", &b); scanf("%lf", &c); if (a<b && b<c) d = b; printf("%.0f\n", d); else if (b<a && a<c) d = a; printf("%.0f\n", d); else d = c; printf("%.0f\n", d); return 0; } That is my code, I keep getting an error for the else if and else saying there is no...