Thread: (C PROGRAM IN VISUAL STUDIO) Stuck on a Calendar Program. (Errr).

  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    9

    (C PROGRAM IN VISUAL STUDIO) Stuck on a Calendar Program. (Errr).

    I have been working on this program as an assignment for more than 15+ hours, it is already more than 3 days past due and this isn't due to me simply being lazy... I have litterally put SOO many hours into trying to understand how to get the outcome necessary and considering this you would think I would get closer, however this is not the case. I am at a stand still and extremely new when it comes to programming which seems like this assignment is pretty cruel and unusual to someone who has never programmed in their lives before. My ranting aside... The program that has been causing so much stress is as follows...

    Code:
    #define _CRT_SECURE_NO_WARNINGS#include <stdio.h>
    
    
    int getdaycode(int month, int year);
    void printheader(int month, int year);
    int getndim(int month, int year);
    
    
    int main()
    {
    	int  day, month, year, nummonths;
    	{
    		printf("Enter Month, Year, and Number of Months");
    		scanf("%d %d %d", &month, &year, &nummonths);
    		
    		for (nummonths; nummonths < 13; nummonths++)
    			if (nummonths > 13)
    				year = year + 1;
    
    
    		printheader(month, year);
    		int numdays = getndim(month, year);
    		int daycode = getdaycode(month, year);
    		
    		for (day = 1; day <= 1 + daycode * 1; day++)
    			printf(" ");
    		
    		for (day = 1; day <= numdays; day++) 
    		
    		{
    			printf("%4d", day);
    			if (daycode % 7 > 0)
    
    
    				printf("   ");
    			else
    				printf("\n");
    		}
    		daycode = numdays % 7;
    	}
    }
    
    
    
    
    int getdaycode(int month,  int year)
    {
    	int numdays;
    	{
    		numdays = ((year - 1) * 365 + ((year - 1) / 4) - ((year - 1) / 100) + ((year - 1) / 400)); // how many days including exceptions
    
    
    		if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))		//check if leapyear
    		{
    			if (month == 1)							// January 
    				numdays = numdays;
    			if (month == 2)							// February 
    				numdays = numdays + 31;
    			if (month == 3)							// March 
    				numdays = numdays + 28 + 31 + 1;
    			if (month == 4)							// April 
    				numdays = numdays + 31 + 28 + 31 + 1;
    			if (month == 5)							// May 
    				numdays = numdays + 30 + 31 + 28 + 31 + 1;
    			if (month == 6)							// June 
    				numdays = numdays + 31 + 30 + 31 + 28 + 31 + 1;
    			if (month == 7)							// July 
    				numdays = numdays + 30 + 31 + 30 + 31 + 28 + 31 + 1;
    			if (month == 8)							// August 
    				numdays = numdays + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
    			if (month == 9)							// September 
    				numdays = numdays + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
    			if (month == 10)							// October						
    				numdays = numdays + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
    			if (month == 11)							// November
    				numdays = numdays + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
    			if (month == 12)							// December
    				numdays = numdays + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31 + 1;
    		}
    		else
    		{
    			if (month == 1)							// January 
    				numdays = numdays;
    			if (month == 2)							// February 
    				numdays = numdays + 31;
    			if (month == 3)							// March 
    				numdays = numdays + 28 + 31;
    			if (month == 4)							// April 
    				numdays = numdays + 31 + 28 + 31;
    			if (month == 5)							// May 
    				numdays = numdays + 30 + 31 + 28 + 31;
    			if (month == 6)							// June 
    				numdays = numdays + 31 + 30 + 31 + 28 + 31;
    			if (month == 7)							// July 
    				numdays = numdays + 30 + 31 + 30 + 31 + 28 + 31;
    			if (month == 8)							// August 
    				numdays = numdays + 31 + 30 + 31 + 30 + 31 + 28 + 31;
    			if (month == 9)							// September 
    				numdays = numdays + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
    			if (month == 10)							// October						
    				numdays = numdays + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
    			if (month == 11)							// November
    				numdays = numdays + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
    			if (month == 12)							// December
    				numdays = numdays + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 + 28 + 31;
    		}
    
    
    		int daycode = numdays % 7;
    		switch (daycode)
    		{
    		case 0:
    			printf("Sunday\n");
    			break;
    
    
    		case 1:
    			printf("Monday\n");
    			break;
    
    
    		case 2:
    			printf("Tuesday\n");
    			break;
    
    
    		case 3:
    			printf("Wednesday\n");
    			break;
    
    
    		case 4:
    			printf("Thursday\n");
    			break;
    
    
    		case 5:
    			printf("Friday\n");
    			break;
    
    
    		case 6:
    			printf("Saturday\n");
    			break;
    
    
    		default: printf("unexpected error (daycode case) daycode = %d", daycode);
    			break;
    		}
    		return daycode;
    	}
    }
    
    
    void printheader(int month, int year)
    	{
    			printf("%14d %1d\n", month, year);
    			printf("Sun ");
    			printf("Mon ");
    			printf("Tue ");
    			printf("Wed ");
    			printf("Thu ");
    			printf("Fri ");
    			printf("Sat\n");
    		}
    
    
    int getndim(int month, int year)
    {
    	int numdays;
    	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))		//check if leapyear
    	{
    		if (month == 1)							// January 
    			numdays = 31;
    		if (month == 2)							// February 
    			numdays = 29;
    		if (month == 3)							// March 
    			numdays = 31;
    		if (month == 4)							// April 
    			numdays = 30;
    		if (month == 5)							// May 
    			numdays = 31;
    		if (month == 6)							// June 
    			numdays = 30;
    		if (month == 7)							// July 
    			numdays = 31;
    		if (month == 8)							// August 
    			numdays = 31;
    		if (month == 9)							// September 
    			numdays = 30;
    		if (month == 10)							// October						
    			numdays = 31;
    		if (month == 11)							// November
    			numdays = 30;
    		if (month == 12)							// December
    			numdays = 31;
    	}
    	else
    	{
    		if (month == 1)							// January 
    			numdays = 31;
    		if (month == 2)							// February 
    			numdays = 28;
    		if (month == 3)							// March 
    			numdays = 31;
    		if (month == 4)							// April 
    			numdays = 30;
    		if (month == 5)							// May 
    			numdays = 31;
    		if (month == 6)							// June 
    			numdays = 30;
    		if (month == 7)							// July 
    			numdays = 31;
    		if (month == 8)							// August 
    			numdays = 31;
    		if (month == 9)							// September 
    			numdays = 30;
    		if (month == 10)							// October						
    			numdays = 31;
    		if (month == 11)							// November
    			numdays = 30;
    		if (month == 12)							// December
    			numdays = 31;
    	}
    	return numdays;
    }
    The 3 functions that follow the main all work as they are intended. However the problem is I don't know how to make them interact within the main function to follow the lines of code as I have placed them. I am simply trying to use my functions of Getdaycode which finds out the day of the week and multiplying this daycode value from it's function by the starting day of the month specified by a scanf("%d %d", &month, &year). The second function is simply my header which I wanted to be the top of my calendar which should have the month NAME instead of the number value I keep getting along with the year, above a row of the days marked in 3 letter abbreviations. The final function is Getnumber of days in month. This will basically just mark the months of the year and mark how many days are in each of these months. If it is a leap year February will have 29 days instead of 28 is basically the only exception here. So again these 3 functions should be working fine, at least mostly. My biggest problem is my main code. (I'm away of the mess of a code this is but still I am pretty sick of it and would REALLY appreciate any help on the matter).
    Last edited by Tyler Botelho; 03-15-2016 at 01:38 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,658
    > void main()
    main returns int, not void.

    > scanf("%d %d %d", &month, &year, &nummonths);
    > void printheader(int month, int year);
    > int getndim(int month, int year);
    > int getdaycode(int month, int day, int year);
    You're not calling the functions, you're just repeating the prototypes.

    These are calls
    printheader( month, year);
    int day = getndim( month, year);
    int code = getdaycode( month, int day, year);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2016
    Posts
    9
    Ok, Let me mess around with it some more and see if I can understand this.

  4. #4
    Registered User
    Join Date
    Mar 2016
    Posts
    9
    Can I set my main like this? > int main (int month, int day, int year) (so that month, day, and year are universally available throughout my code)?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,658
    > Can I set my main like this? > int main (int month, int day, int year) (so that month, day, and year are universally available throughout my code)?
    No, you're guessing again.
    Read your primary sources to find out about
    - how main is declared
    - how to call a function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Mar 2016
    Posts
    9
    That's the problem and why I am have SOO much trouble. I Have NO primary sources. I was just thrown into this assignment with nothing to refer to. I have been working on what should seem to be simple for probably over 20 hours at this point. And it is already over 3 days late so that doesn't really give leeway to learn the whole language at this point in time. That is why I just wanted to work through step by step with that I already DO have. As I'm hoping after having worked on this for sooooo long it should be close to completion in some respect.

  7. #7
    Registered User
    Join Date
    Mar 2016
    Posts
    9
    Made more changes and it is starting to come together a bit more, not sure why the Day is showing up though, and all the numbers arn't aligned correctly.

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    4,508
    Also here.

    >> I Have NO primary sources.

    You really should be using a book to help you learn the language - but even without that, even online tutorials should suffice.

    >> I was just thrown into this assignment with nothing to refer to.

    If this is an assignment, it stands to reason that you should have a little experience with the concepts required. If not, open a book (or tutorial) and start reading.

    >> I have been working on what should seem to be simple for probably over 20 hours at this point. And it is already over 3 days late so that doesn't really give leeway to learn the whole language at this point in time.

    If you haven't learned (and practiced with) the necessary material on the basics, then no amount of time will yield a successful program. And without this background, there is no advice we could give that would help you.

    Your only chance is to start from the beginning - get a book, read each chapter, type out all the examples, do all the problems and exercises, and start building your knowledge.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to run a c program on visual studio command prompt
    By Dawud.Beale in forum C Programming
    Replies: 8
    Last Post: 02-07-2012, 05:01 PM
  2. Help! Visual Studio 6 Newb I'm stuck on first program
    By Hybodus in forum Windows Programming
    Replies: 2
    Last Post: 06-08-2011, 06:34 AM
  3. Executing C Program in Visual Studio 2008
    By rory-uk in forum C Programming
    Replies: 29
    Last Post: 07-10-2009, 01:53 PM
  4. Replies: 10
    Last Post: 04-07-2008, 09:14 AM
  5. C++ console program using Ms Visual Studio .NET
    By matheo917 in forum C++ Programming
    Replies: 4
    Last Post: 09-05-2002, 11:16 PM

Tags for this Thread