RSS Forums RSS
Please support our C advertiser: Programming Forums
Views: 1967 | Replies: 18
Reply
Join Date: Mar 2006
Posts: 7
Reputation: neo69potato is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
neo69potato neo69potato is offline Offline
Newbie Poster

Help Hi need help with this pretty please =)

  #1  
Mar 20th, 2006
ok basically me and a friend are learning C language and we're totally stuck on this problem in the textbook and want to get around it before moving on.
We're totally useless so a nudge in the right direction or any help at all would be awesome.

heres the problem:

Write a program to compute and print the day of Easter Sunday in 2006. The output should be in the form:

Month m, day n.

Where m is the month number (3 for March, 4 for April), and n is the day in the month.

The date for Easter Sunday is March(22 + a + b), where

a = (19c + 24) remainder 30
b = (2d + 4e + 6a + 5) remainder 7
c = year remainder 19
d = year remainder 4
e = year remainder 7

If (22 + a + b) is greater than 31, the date is in April.
You will need to do a division and remainder to correct for this.

Make sure that your program also works for other years - including 1991, 1997 and 2018!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Hi need help with this pretty please =)

  #2  
Mar 20th, 2006
Hullo,

You need to use the modulus operator to get the remainder. The rest is simple as pie. I can't envisage any other problems.
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Mar 2006
Posts: 7
Reputation: neo69potato is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
neo69potato neo69potato is offline Offline
Newbie Poster

Re: Hi need help with this pretty please =)

  #3  
Mar 20th, 2006
Cool thanks looking into it now in the book. =)

anything else?

remember we are complete programming retards =S
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 11,070
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 33
Solved Threads: 118
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: Hi need help with this pretty please =)

  #4  
Mar 20th, 2006
We use the / operator to signify integer division. Basically what it means is to throw away the remainder. Therefore, 6 / 3 = 2 but 7 / 3 = 2 as well.

Modular division is remainder division and its operator is the percent sign. It means to throw away the integer and only keep the remainder. Therefore, 7 % 3 = 1 and 9 % 5 = 4.
Dani the Computer Science Gal
Reply With Quote  
Join Date: Mar 2006
Posts: 7
Reputation: neo69potato is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
neo69potato neo69potato is offline Offline
Newbie Poster

Re: Hi need help with this pretty please =)

  #5  
Mar 20th, 2006
Cool thanks for helping us get on the right track =)

Any more help would be much appreciated =)
Reply With Quote  
Join Date: Mar 2006
Posts: 7
Reputation: neo69potato is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
neo69potato neo69potato is offline Offline
Newbie Poster

Re: Hi need help with this pretty please =)

  #6  
Mar 20th, 2006
ok tried a few things and ended up with this yet still nothing.
we're very useless someone plzzzz help!

/*This program will print the day of Easter Sunday in 2006*/

#include <stdio.h>

int main () {

float a,b,c,d,e;

a = (19c + 24) remainder 30;
b = (2d + 4e + 6a + 5) remainder 7;
c = year remainder 19;
d = year remainder 4;
e = year remainder 7;

printf("a=%a b=%a",d,e);
}



that basically doesnt run and gives alot of errors please help!
Reply With Quote  
Join Date: Sep 2004
Posts: 6,578
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 499
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Hi need help with this pretty please =)

  #7  
Mar 20th, 2006
>that basically doesnt run and gives alot of errors
That's no surprise. remainder is neither a keyword nor an operator, so the compiler looks for an identifier that you've defined. Because you haven't done so, an error is thrown. You also haven't defined year, so the same problem exists for that.

The remainder operator is %, but it doesn't work on floating-point values. For that you need to use the fmod function in <math.h>.

The way you translated the equations suggests you don't realize that C has an operator for multiplication, *. You don't simply merge the two operands to get the product; the compiler can't parse that.

Because double is the default type for floating-point, you would have an easier time avoiding the float type and going straight to double.

c, d, and e are uninitialized when you first use them. It looks like you haven't ordered your statements properly. c should be initialized before a with d and e initialized before b. Better names would do you a world of good.

The %a format modifier only exists for C99, and most compilers aren't compatible with C99. %f would suit you better at this point.

Finally, main returns an integer, so you would do well to actually make good on that by returning an integer.
#include <stdio.h>
#include <math.h>

int main ( void )
{
  double a, b, c, d, e;
  int year = 2006;

  c = fmod ( year, 19.0 );
  a = fmod ( 19 * c + 24, 30 );
  d = fmod ( year, 4.0 );
  e = fmod ( year, 7.0 );
  b = fmod ( 2 * d + 4 * e + 6 * a + 5, 7 );

  printf ( "a = %.2f\nb = %.2f\n", d, e );

  return 0;
}
I'm here to prove you wrong.
Reply With Quote  
Join Date: Mar 2006
Posts: 7
Reputation: neo69potato is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
neo69potato neo69potato is offline Offline
Newbie Poster

Re: Hi need help with this pretty please =)

  #8  
Mar 20th, 2006
hmmm ok thanks.

We're trying to get our minds around your program, but when we ran it, it didnt actually do what the problem asks of it to do.

Where do we need to go from here?
Reply With Quote  
Join Date: Sep 2004
Posts: 6,578
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 499
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Hi need help with this pretty please =)

  #9  
Mar 20th, 2006
>Where do we need to go from here?
Understand the calculations that you're asked to perform and adjust the code accordingly. I fixed legitimate errors and only guestimated on the logic. If you want help with the logic, you'll need to be more specific about the problem (ie. what input you'll give, what output you're getting, what output you expect, and a breakdown of how the formulae work for our less mathematically inclined helpers).
I'm here to prove you wrong.
Reply With Quote  
Join Date: Mar 2006
Posts: 7
Reputation: neo69potato is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
neo69potato neo69potato is offline Offline
Newbie Poster

Re: Hi need help with this pretty please =)

  #10  
Mar 20th, 2006
Thanks =D
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:43 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC