Hi,
I'm trying to get a program started but seem to have fallen at the first hurdle. :-(
Please find my code below. When executed it gets as far as the second switch statement then stops running, asking me to press any key to continue and closing the terminal window. Does anybody know if it's possible to nest switches in this way? Can you see where I'm going wrong?
Code:
#include <stdio.h>
int main(void)
{
int month, first, i = 0;
printf("Which month would you like to view?");
scanf("%d", &month);
switch (month) {
case 1: printf("On which day does this month begin? ");
scanf("%d", &first);
printf("\n\nJanuary\n\nSun\tMon\tTue\tWed\tThu\tFri\tSat\n\n");
switch (first) {
case 1: printf("");
break;
case 2: printf("\t");
i = 1;
break;
case 3: printf("\t\t");
i = 2;
break;
case 4: printf("\t\t\t");
i = 3;
break;
case 5: printf("\t\t\t\t");
i = 4;
break;
case 6: printf("\t\t\t\t\t");
i = 5;
break;
case 7: printf("\t\t\t\t\t\t");
i = 6;
break;
default: printf("An error has occured, please restart the program!");
break;
}
for (; i > 31; i++) {
printf("%d\t", i);
if (i > 6) {
printf("\n\n");
}
}
}
return 0;
}