Originally posted by kermit
Here is what I had figured out today while I was at work - I hate that when I can't get to a computer to test it out - And I didn't really have any time to work it out on paper anyway.
I see that Azimuth's code works, but I have not had time to really check it out.
Yeah, both work. I appreciate you guys helping me understand this stuff better. After looking at the way kermit did his code I figured it out why you need that extra 1. Came up w/ this after error checking:
Code:
#include <stdio.h>
main()
{
int i=0; /* Intialize i, n, day, & blank */
int n=0;
int day=0;
int blank=0;
/* Ask user for amount of days */
printf("Enter number of days in the month:");
/* Checks if valid amount of days */
while ( scanf("%d", &n) != n > 28 || n > 31)
{
printf("Not a correct number of days! Please try again!");
}
/* Ask user for start of week */
printf("Enter starting day of the week (1=Sun, 7=Sat):");
/* Checks if valid day */
while ( scanf("%d", &day) != day > 1 || day > 7)
{
printf("Not a correct choice of start days! Please try again!");
}
/* Print out headers of days */
printf(" S M T W T F S \n\n");
/* Blank equals one. If blank is > then day, */
/* print spaces. Increment blank, print spaces */
/* until day is < blank */
for ( blank = 1; day > blank; blank++ )
{
printf(" ");
}
/* Start off at zero, if i is < then amount of */
/* days increment by one. Until > then the days*/
for (i=0; i < n ; i++)
{ /* Print out i's looped, then add one */
printf("%3d", (i+1));
/* When mod. equals zero, end line & start new */
if ( (i + day) % 7 == 0)
{
printf("\n");
}
}
}
Look ok to you guys?