Hello, I am new to C, and I need to create a calendar, where the user inputs the days of the month and what day the calendar starts on, such as Mo, Tu, we, etc, and show a calendar. I have the calendar output the correct number of days with formatting, but do not know how to start on a specific day? I am wondering how to turn the string of characters (we, th) into a number 1-7, I am thinking that would be the solution. Also, I need to show an error message if the starting day is not correct (ex. tg, mi). Here is my code:
as you can see I have certain parts taken out as a comment, because it did not work.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int
main()
{
int num_days;
int i;
char day;
char day2;
printf("This prigram displays the calender for a month.\n\n\n");
printf("Enter number of days in month: \n");
scanf("%i", &num_days);
printf("Enter starting day of the week (Su,Mo,Tu,...,Sa): \n");
scanf("%*[ \n]%c", &day);
//if (day != "Su" || day != "Mo" || day != "Tu" || day != "We" || day != "Th" || day != "Fr" || day != "Sa" || day != "su" || day != "mo" || day != "tu" || day != "we" || day != "th" || day != "fr" || day != "sa")
// printf("That is an invalid day of the week.");
//else {
day2 = toupper(day);
printf("%c\n", day2);
//}
printf(" Su Mo Tu We Th Fr Sa\n");
for (i = 1 ; i < num_days + 1 ; ++i ){
printf("%3i ", i);
if(i % 7 == 0)
printf("\n");
}
printf("\n");
}
Here is my latest attempt, which still does not work:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int
main()
{
int num_days;
char day;
char day2;
char Su, su;
char Mo, mo;
char Tu, tu;
char We, we;
char Th, th;
char Fr, fr;
char Sa, sa;
printf("This program displays the calender for a month.\n\n\n");
printf("Enter number of days in month: \n");
scanf("%i", &num_days);
printf("Enter starting day of the week (Su,Mo,Tu,...,Sa): \n");
scanf("%*[ \n]%c", &day);
day2 = toupper(day);
printf("%c\n", day2);
printf(" Su Mo Tu We Th Fr Sa\n");
if (day == Su || day == su)
printf("");
else if (day == Mo || day == mo)
printf(" ");
else if (day == Tu || day == tu)
printf(" ");
else if (day == We || day == we)
printf(" ");
else if (day == Th || day == th)
printf(" ");
else if (day == Fr || day == fr)
printf(" ");
else if (day == Sa || day == sa)
printf(" ");
int count;
for (count = 1 ; count < num_days + 1 ; count++ ){
printf("%3d ", count);
if(count % 7 == 0)
printf("\n");
}
}
Thanks for the help!!!