# help with basic c program.

This is a discussion on help with basic c program. within the C Programming forums, part of the General Programming Boards category; My professor assigned us an "easy" project in his words for our intro to c programming class. we use visual ...

1. ## help with basic c program.

My professor assigned us an "easy" project in his words for our intro to c programming class. we use visual studio.net 2003. I really have no idea where to start or what to do. Could someone help give me a jumpstart or something? heres the problem he wants us to write a program for:

The ACME company is producing a personal planner/scheduler and needs your help in producing its
automated calendar. It needs to populate holidays into its calendar and needs a program that will
compute the date for Easter for a given year. Your task is to write a program that will input a year and
will output the date (month and day) of Easter for that year.
It is possible to compute the date for any Easter Sunday from 1982 to 2048 using the following steps.
• Step 1: compute a as year % 19
• Step 2: compute b as year % 4
• Step 3: compute c as year % 7
• Step 4: compute d as (19a + 24) % 30
• Step 5: compute e as (2b + 4c + 6d + 5) % 7
• Step 6: compute f as d + e
The date for Easter Sunday, then, is f days after March 22. Note that it is possible that f is large
enough to correspond to a date in April.
Objectives

2. Originally Posted by kermi3
Welcome to the boards. If you haven't already done so then please take some time to familiarise yourself with the faq:
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Make sure you have a look at the the posting guidelines:
http://cboard.cprogramming.com/annou...ouncementid=51
Following the rules will ensure you get a prompt answer to your question.

Remember, too, that the board has a search facility, a link is at the top of your screen:
http://cboard.cprogramming.com/search.php
It will often get you a quicker answer to your questions than waiting for a response to one you have posted.

It appears that you are posting a homework assignment or other project.

Please don't ask people to do all your work for you, See the announcement on Homework at the top of all forums to see what is acceptable or PM me. Basically people are happy to help, but they're not going to do it all for you.

Show us what you've got, show your code (using code tags), or where you're confused and someone will be happy to help you I'm sure. If it's something that you absolutely don't understand how it works, like you have no clue how qsort works, then ask a general question about the function and I'm sure someone will explain it. Though they may not give you all of the code for it, but someone will explain the concept.

On obivous homework questions especially, I like to remind people of the board's ninth guildeline, while this board is very helpful to people, make sure you have your instructor's permission before seeking help on assignments. While people on these boards are more than happy to help, we discourage people from asking for help on graded work without the instructor's permission, and we claim no repsonsibilty for any cheating or honor violations.

Feel free to PM me with any questions.

Good Luck,

Kermi3

Read and follow the above instructions, and try your post (in the same thread) again.

Quzah.

3. I know we aren't supposed to help people with homework but I wrote this up real quick. It's written in C++ but hopefully you can port it to C, and learn from it. Attached.

4. thanks jmd15....here is my attempt at writing this one out in c. I cant figure out what goes before and after == in the if statements and what should be at the end of the print f statements...did i hit anywhere in the ballpark with this?

Code:
```#include <stdio.h>

int main(void)
{
int year;
int A,B,C,D,E,G;

printf("Please type the year: ");
scanf("%d",&year);

A = year%19;
B = year%4;
C = year%7;
D = (19*A+24)%30;
E = (2*B+4*C+6*D+5)%7;
G = D+E;

if ( == )
printf("Easter is on March %d\n",);
else if ( == )
printf("Easter is on April %d\n",);
else
printf("There is an error in the formula.\n");

return 0;
}```

5. For the if statements put:
Code:
```G+=22;
if (G<=31)
printf("Easter is on March %d\n",);
else if (G>31)
G-=31;
printf("Easter is on April %d\n",);```
You add 22 because that formula tells how many days Easter is after March 22. The 31 is there because March is 31 days long. Hope that helps.

6. so would this be the final correctly working code? I tested it and it seems to be correct but i may be wrong.

Code:
```#include <stdio.h>

int main(void)
{
int year;
int A,B,C,D,E,G;

printf("Please type the year: ");
scanf("%d",&year);

A = year%19;
B = year%4;
C = year%7;
D = ((19 * A)+24) % 30;
E = ((2 * B) + (4 * C) + (6 * D) + 5) % 7;
G = D+E;

G+=22;
if (G<=31)
printf("Easter in %d is on March %d\n",year,G);

else if (G>31)
G-=31;
printf("Easter in %d is on April %d\n",year,G);

return 0;
}```

7. Originally Posted by Uber Fr0g
Code:
```else if (G>31)
G-=31;
printf("Easter in %d is on April %d\n",year,G);```
The if statements don't need brackets({}) because they only have one line of code to execute if that condition is true. However, for your second if statement this isn't true, so just to be safe change the quoted code to this:
Code:
```else if(G>31)
{
G-=31;
printf("Easter in %d is on April %d\n",year,G);
}```
Other than that it looks good to me.

Popular pages Recent additions