The user is asked to input the number of days in a month and the first day of the month. Here is the sample output:

Input the number of days in a month: 30
input the first day of the month: 4
0-Sunday
1-Monday
2-Tuesday
3-Wednesday
4-Thursday
5-Friday
6-Saturday

Sun   Mon   Tues   Wed   Thurs   Fri   Sat
                            1     2     3 
4      5     6      7       8     9     10    
11    12     13     14      15    16    17
18    19     20     21      22    23    24
25    26     27     28      29    30

This is my sample code, but everytime I enter O in the first day of the month, the alignment is lost. :?:Help!!! :mecry: i tired to fix it several times but i can't!!!

#include<stdio.h>
#define p printf
#define s scanf
int TD,D,x,y=1,E;
main()
{
clrscr();
p("Input Number of days in a month:");
s("%d",&TD);
p("Input the first day of the month:");
s("%d",&D);
p("Sun\tMon\tTues\tWed\tThurs\tFri\tSat\n");
for(x=1;x<=42;x++)
{
if(x<=D)
{
printf("\t");
}
else if(y<=TD)
{
E=7-D;
if(y%7==D)
{
printf("%d\n",y);
}
else
{
printf("%d\t",y);
}
y++;
}}
getch();
}

Your code will stay formatted properly, only if you click on the [CODE ] icon in the editing window, and paste your code right between the code tags that the editor gives you:

[CODE ]
<YOUR CODE GOES HERE>
[/CODE ]

Take a look at this. I couldn't quite grasp the logic that was involved in your program.

#include<stdio.h>

#define p printf
#define s scanf

int main()
{
  int totalDays,day,i, j, r, c, firstDay;

  //clrscr();
  printf("\n\n\n");
  p("Input Number of days in a month:");
  s("%d",&totalDays);
  p("Input the first day of the month:");
  s("%d",&firstDay);

  p(" Sun  Mon  Tues  Wed  Thurs  Fri  Sat\n");

  for(r=0,day=0;r<5;r++)
  {
    if(r==0) {     //printing the first row only
      for(j=0;j<7;j++) {
        if(j==2 || j==4 || j==5) //handles days with 4 letters, etc.
          putchar(' ');          //I don't like using tabs
        if(j<firstDay) 
          printf("     ");      //as you can tell ;)
        else
          printf(" %2d  ", ++day);
      }
      putchar('\n');
    }
    for(c=0;c<7;c++) {    //prints all the other rows
      if(++day>totalDays)
        break;
      if(c==2||c==4 ||c==5)
        putchar(' ');     //about the same as the first row
      printf(" %2d  ", day); 
    }
    printf("\n");          
  } 
  getch();
  return 0;
} 

wow!!!You're amazing. You're a great help!!!But there's problem regarding the alignment of the first row.

The alignment for all rows is perfect, on my screen.

What input for total days and first day are you seeing this problem with?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.