Thread: help with basic c program.

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    16

    Cool 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. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote 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.
    Hope is the first step on the road to disappointment.

  3. #3
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    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.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    16
    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. #5
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    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.
    Last edited by jmd15; 09-25-2005 at 08:48 PM.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    16
    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. #7
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Quote 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.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. Basic encryption program???
    By Finchie_88 in forum C++ Programming
    Replies: 14
    Last Post: 09-10-2004, 09:01 AM
  3. IDEA: A basic drawing program
    By ygfperson in forum Contests Board
    Replies: 0
    Last Post: 08-12-2002, 11:15 PM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. Help me with this basic c program
    By [ToXiC]-[LeaK] in forum C Programming
    Replies: 1
    Last Post: 01-28-2002, 11:44 PM