# Calendar Table using Turbo C how?

Page 1 of 1

## 9 Replies - 8530 Views - Last Post: 10 November 2010 - 10:23 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=199337&amp;s=495ac3fd39463776946b4e4463778f24&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Civirol

Reputation: 0
• Posts: 7
• Joined: 10-November 10

# Calendar Table using Turbo C how?

Posted 10 November 2010 - 06:46 AM

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. I enter 1-6 in the first day of the month and it works...but everytime I enter O in the first day of the month, the alignment is lost. Help!!! i tried 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();
}

```

This post has been edited by macosxnerd101: 10 November 2010 - 06:51 AM
Reason for edit:: Added code tags

Is This A Good Question/Topic? 0

## Replies To: Calendar Table using Turbo C how?

### #2 brds

Reputation: 76
• Posts: 515
• Joined: 22-October 08

## Re: Calendar Table using Turbo C how?

Posted 10 November 2010 - 08:50 AM

Your provided code dose not work for any case (0-6). I had to change if(y%7==D) to if(y%7==E) to make it work as you described. Your main problem is this:
```E=7-D;
if(y%7==E)

```

With a zero value for D, E is 7, thus y%7 will never be equal to 7 as % only returns the remainder. So you gotta make an E value of 7 into 0 before you hit the if statement.

### #3 Civirol

Reputation: 0
• Posts: 7
• Joined: 10-November 10

## Re: Calendar Table using Turbo C how?

Posted 10 November 2010 - 09:13 AM

brds, on 10 November 2010 - 07:50 AM, said:

Your provided code dose not work for any case (0-6). I had to change if(y%7==D) to if(y%7==E) to make it work as you described. Your main problem is this:
```E=7-D;
if(y%7==E)

```

With a zero value for D, E is 7, thus y%7 will never be equal to 7 as % only returns the remainder. So you gotta make an E value of 7 into 0 before you hit the if statement.

Do I need to change my formula or equate E to 0? Or do I need to make another for loop before the if function?

This post has been edited by Civirol: 10 November 2010 - 09:15 AM

### #4 brds

Reputation: 76
• Posts: 515
• Joined: 22-October 08

## Re: Calendar Table using Turbo C how?

Posted 10 November 2010 - 09:19 AM

A simple if statement will suffice, or you can get fancy with E %= 7; after the E = 7 - D;.
```E = 7 - D;
E %= 7; /* Set E to the remainder of E/7 */

```

@Edit: typo.

This post has been edited by brds: 10 November 2010 - 09:23 AM

### #5 brds

Reputation: 76
• Posts: 515
• Joined: 22-October 08

## Re: Calendar Table using Turbo C how?

Posted 10 November 2010 - 09:25 AM

Or do it in one line
```E = (7 - D) % 7;

```

### #6 Civirol

Reputation: 0
• Posts: 7
• Joined: 10-November 10

## Re: Calendar Table using Turbo C how?

Posted 10 November 2010 - 09:44 AM

brds, on 10 November 2010 - 08:19 AM, said:

A simple if statement will suffice, or you can get fancy with E %= 7; after the E = 7 - D;.
```E = 7 - D;
E %= 7; /* Set E to the remainder of E/7 */

```

@Edit: typo.

Thank you so much for the information!!! It finally works!!! You're great!!!

### #7 baavgai

• Dreaming Coder

Reputation: 7181
• Posts: 14,969
• Joined: 16-October 07

## Re: Calendar Table using Turbo C how?

Posted 10 November 2010 - 09:52 AM

Civirol, on 10 November 2010 - 07:46 AM, said:

```#define p printf
#define s scanf

```

This level of lazy boggles the mind.

• Saucy!

Reputation: 6246
• Posts: 24,014
• Joined: 23-August 08

## Re: Calendar Table using Turbo C how?

Posted 10 November 2010 - 09:58 AM

Typical Turbo C code.

### #9 brds

Reputation: 76
• Posts: 515
• Joined: 22-October 08

## Re: Calendar Table using Turbo C how?

Posted 10 November 2010 - 10:14 AM

baavgai++

Some day we will live in a world without Turbo C, and we will all have are very own flying pigs.

### #10 Civirol

Reputation: 0
• Posts: 7
• Joined: 10-November 10

## Re: Calendar Table using Turbo C how?

Posted 10 November 2010 - 10:23 AM

Thank you so much! I'm just a new student taking computer science, so i have difficulty in simple c problems. thanks!!!