Implement a function that prints the calendar for a given month and year. First, prompt the user:
Enter the month and year:
Once the user enters a valid input (two integers separated by a space), print out the calendar in a format be similar to the output of the UNIX cal
command. For example, if the user enters 03 2014
, the output should be:
I need help with being able to ask the user for the specific input that this question is asking for. I am also having trouble with creating code that will be able to print different months based on the input, as each month starts on a different day. I cannot use anything too complex as I'm taking a beginner course in programming.
The code I have so far for only printing out March:
#include <stdio.h>
int main()
{
int k, rmd;
printf(" March 2014\n");
printf(" Su Mo Tu We Th Fr Sa\n");
for(k = 1; k < 32; ++k) {
if(k == 1){
printf(" %2d\n", k);
}
else if(k % 7 == 1) {
printf(" %2d\n", k);
}
else {
printf(" %2d", k);
}
}
return 0;
}