Plz help me C programm

This is a discussion on Plz help me C programm within the C Programming forums, part of the General Programming Boards category; Using this file Calendar.c Code: #include <stdio.h> #include <header.h> main() { char dummy; int i, end_of_line, days_in_month=30; printf("Please enter a ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    4

    Plz help me C programm

    Using this file

    Calendar.c
    Code:
    #include <stdio.h>
    #include <header.h>
    main()
    {
    	char dummy;
    	int i, end_of_line, days_in_month=30; 
    	printf("Please enter a year: ");
    	scanf("%i", &a.year);
    	printf("Please enter a month: (1=Jan, 12=Dec): ");
    	scanf("%i",&a.month);
    	printf("Please enter the starting day of the month (1=Sun, 7=Sat): ", &a.starting_day);
    	scanf("%i", &a.starting_day);
    	/* call function to determine the number of days in the month*/
    	
    	printf("S\tM\tT\tW\tT\tF\tS\n");
    	switch (a.starting_day)
    		{
    			case 1: end_of_line=7;
    			break;
    			case 2: end_of_line=6;
    				printf("\t");
    			break;
    			case 3: end_of_line=5;
    				printf("\t\t");
    			break;
    			case 4: end_of_line=4;
    				printf("\t\t\t");
    			break;
    			case 5: end_of_line=3;
    				printf("\t\t\t\t");
    			break;
    			case 6: end_of_line=2;
    				printf("\t\t\t\t\t");
    			break;
    			case 7: end_of_line=1;
    				printf("\t\t\t\t\t\t");
    		}
    	
    	for(i=1; i<=days_in_month; i++)
    	{	
    	printf("%i\t",i);	
    		
    	if(end_of_line==1)
    	
    	{	
    	printf("\n");
    	end_of_line=7;
    	}	
    	else
    		end_of_line = end_of_line-1;
    	}
    	
    	
    	scanf("%c", &dummy);
    }
    and calling programs from this

    header.h
    Code:
    struct user_input
    {
    	int year;
    	int month;
    	int starting_day;
    };
    
    struct user_input a;
    giving you the code for the basic calendar program that asks the user to input a month (1=January…12=December), a starting day for the day of the week the calendar starts (1=Sunday…7=Saturday) and the year.

    The code is in a header file named header.h which is up here, and the main program is in a file named calendar.c which is the first one.
    You need to add to the calendar program in the following way:

    Print out the name of the month and the year at the top of the calendar. For example if the user types in 5 for May and 2008 as the year and starting day of 5 they should see
    Code:
    		May 2008
    S	M	T	W	T	F	S 
    				 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	31
    Given the month you will write a function to determine the number of days in the month. September, April, June and November have 30 days, February 28 or 29 depending on leap year and all the rest of the months 31. The calendar.c file currently defaults to printing out 30 days.

    Leap years are years that are evenly divisible by 4 or 100. (Hint: mod operation)

    The function should be in a separate file named months.c
    The main program should continue to run until the user wants to stop printing calendars.

    Add error checking, for example the month value must be a number between 1 and 12.

    Please help me to resolve this, and explain a little bit, because i really cant figure out what i am doing wrong even from the beggining. Thanks again for your time, and your help.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The program seems quite straight forward.

    I don't see any of your work on it, anywhere, and you don't mention any specific problem.

    We can't teach you the class material in C, on the forum. You should be looking at your book/handouts, and class notes, perhaps discussing it with your classmates and your teacher.

    Show us your work/attempt, and ask a specific question related to that work.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    4
    Classes are over and unfortunately i didnt make friends at the class, and you dont even know how long i have been trying to do this, and if i didnt post my work is because is messy and you wouldnt be able to understand it.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by ferroz1 View Post
    Classes are over and unfortunately i didnt make friends at the class, and you dont even know how long i have been trying to do this, and if i didnt post my work is because is messy and you wouldnt be able to understand it.
    Wrong!

    I'd understand because I was a student myself, and more importantly, I'd understand that you were ACTUALLY TRYING to solve the problem.

    You can't imagine how many people post on this forum, some program they've found, and hope that someone will just "fix it", "modify it", etc., and do NOT ONE BIT OF WORK on it themselves.

    So post your work, and let's see what's up. You won't learn anything by me doing the work - and the sooner you learn that, the better for you.

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    4
    can you at least explain to me in steps what i have to do, because i think thats what i am doing wrong, i cant even start it right. I am confused on what the assignment is asking me, can u put them into steps anyone plz.

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    4
    I did it but i dont know why is not working if anyone plz help me and tell me what to change because my program is not ending and the leap year (february which only has 29 0r 28 days is not working) plz help me
    Code:
    #include <stdio.h>
    #include "header.h"
    
    
    int isLeapYear(int year)
    {
       int isLeap = 0;
       if((year &#37; 4) == 0) 
         {
         isLeap = 1;
         if((year % 100) == 0) 
           {
           isLeap = 0;
           if((year % 400) == 0)
             {
             isLeap = 1;
             }
           } 
         }
       return isLeap;
    }
    
    
    int getMonthDays(int month, int year){
        int days = 0;
        switch(month){
          case 1: days = 31; 
          break;
          case 2: if(isLeapYear(year) == 1)
                      days = 29;
                  else 
                      days = 28;
                  break;
          case 3: days = 31; break;
          case 4: days = 30; break;
          case 5: days = 31; break;
          case 6: days = 30; break;
          case 7: days = 31; break;
          case 8: days = 31; break;
          case 9: days = 30; break;
          case 10: days = 31; break;
          case 11: days = 30; break;
          case 12: days = 31; break;
          }
        return days;    
      }
    
    
    main()
    {
    	char dummy;
    	int i, end_of_line, days_in_month=30; 
    	
    	while(dummy != 'N' || dummy != 'n')
    {
        printf("Please enter a year: ");
    	scanf("%i", &a.year);
    	printf("Please enter a month: (1=Jan, 12=Dec): ");
    	scanf("%i",&a.month);
    	while(a.month< 1 || a.month> 12){
            printf("\n\nInvalid input: Enter valid input\n");
            printf("Please enter a month: (1=Jan, 12=Dec): ");
    	    scanf("%i",&a.month);    
         }
    	printf("Please enter the starting day of the month (1=Sun, 7=Sat): ", &a.starting_day);
    	scanf("%i", &a.starting_day);
    	while(a.starting_day < 1 || a.starting_day > 7)
    {
            printf("\n\nInvalid input: Enter valid input\n");
            printf("Please enter the starting day of the month (1=Sun, 7=Sat): ", &a.starting_day);
    	scanf("%i", &a.starting_day);   
    }
    	
    	
    	printf("S\tM\tT\tW\tT\tF\tS\n");
    	switch (a.starting_day)
    		{
    			case 1: end_of_line=7;
    			break;
    			case 2: end_of_line=6;
    				printf("\t");
    			break;
    			case 3: end_of_line=5;
    				printf("\t\t");
    			break;
    			case 4: end_of_line=4;
    				printf("\t\t\t");
    			break;
    			case 5: end_of_line=3;
    				printf("\t\t\t\t");
    			break;
    			case 6: end_of_line=2;
    				printf("\t\t\t\t\t");
    			break;
    			case 7: end_of_line=1;
    				printf("\t\t\t\t\t\t");
    		}
    	
    	for(i=1; i<=days_in_month; i++)
    	{	
    	printf("%i\t",i);	
    		
    	if(end_of_line==1)
    	
    	{	
    	printf("\n");
    	end_of_line=7;
    	}	
    	else
    		end_of_line = end_of_line-1;
    	}
        
        printf("\n\nDo you want to continue? (Y/N):   ");    	
    	scanf("%c", &dummy);scanf("%c", &dummy);
    	if(dummy == 'n' || dummy =='N')
    	break;
       }
       
       printf("\nProgramming Ended. Press Enter key to exit.....\n");
       scanf("%c", &dummy);scanf("%c", &dummy);
    }

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    Hai i am getting so many errors

    Quote Originally Posted by ferroz1 View Post
    I did it but i dont know why is not working if anyone plz help me and tell me what to change because my program is not ending and the leap year (february which only has 29 0r 28 days is not working) plz help me
    Code:
    #include <stdio.h>
    #include "header.h"
    
    
    int isLeapYear(int year)
    {
       int isLeap = 0;
       if((year % 4) == 0) 
         {
         isLeap = 1;
         if((year % 100) == 0) 
           {
           isLeap = 0;
           if((year % 400) == 0)
             {
             isLeap = 1;
             }
           } 
         }
       return isLeap;
    }
    
    
    int getMonthDays(int month, int year){
        int days = 0;
        switch(month){
          case 1: days = 31; 
          break;
          case 2: if(isLeapYear(year) == 1)
                      days = 29;
                  else 
                      days = 28;
                  break;
          case 3: days = 31; break;
          case 4: days = 30; break;
          case 5: days = 31; break;
          case 6: days = 30; break;
          case 7: days = 31; break;
          case 8: days = 31; break;
          case 9: days = 30; break;
          case 10: days = 31; break;
          case 11: days = 30; break;
          case 12: days = 31; break;
          }
        return days;    
      }
    
    
    main()
    {
    	char dummy;
    	int i, end_of_line, days_in_month=30; 
    	
    	while(dummy != 'N' || dummy != 'n')
    {
        printf("Please enter a year: ");
    	scanf("%i", &a.year);
    	printf("Please enter a month: (1=Jan, 12=Dec): ");
    	scanf("%i",&a.month);
    	while(a.month< 1 || a.month> 12){
            printf("\n\nInvalid input: Enter valid input\n");
            printf("Please enter a month: (1=Jan, 12=Dec): ");
    	    scanf("%i",&a.month);    
         }
    	printf("Please enter the starting day of the month (1=Sun, 7=Sat): ", &a.starting_day);
    	scanf("%i", &a.starting_day);
    	while(a.starting_day < 1 || a.starting_day > 7)
    {
            printf("\n\nInvalid input: Enter valid input\n");
            printf("Please enter the starting day of the month (1=Sun, 7=Sat): ", &a.starting_day);
    	scanf("%i", &a.starting_day);   
    }
    	
    	
    	printf("S\tM\tT\tW\tT\tF\tS\n");
    	switch (a.starting_day)
    		{
    			case 1: end_of_line=7;
    			break;
    			case 2: end_of_line=6;
    				printf("\t");
    			break;
    			case 3: end_of_line=5;
    				printf("\t\t");
    			break;
    			case 4: end_of_line=4;
    				printf("\t\t\t");
    			break;
    			case 5: end_of_line=3;
    				printf("\t\t\t\t");
    			break;
    			case 6: end_of_line=2;
    				printf("\t\t\t\t\t");
    			break;
    			case 7: end_of_line=1;
    				printf("\t\t\t\t\t\t");
    		}
    	
    	for(i=1; i<=days_in_month; i++)
    	{	
    	printf("%i\t",i);	
    		
    	if(end_of_line==1)
    	
    	{	
    	printf("\n");
    	end_of_line=7;
    	}	
    	else
    		end_of_line = end_of_line-1;
    	}
        
        printf("\n\nDo you want to continue? (Y/N):   ");    	
    	scanf("%c", &dummy);scanf("%c", &dummy);
    	if(dummy == 'n' || dummy =='N')
    	break;
       }
       
       printf("\nProgramming Ended. Press Enter key to exit.....\n");
       scanf("%c", &dummy);scanf("%c", &dummy);
    }

    hai

    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(13) : error C2065: 'a' : undeclared identifier
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(13) : error C2228: left of '.year' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(15) : error C2228: left of '.month' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(16) : error C2228: left of '.starting_day' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(17) : error C2228: left of '.starting_day' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(21) : error C2228: left of '.starting_day' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(60) : warning C4508: 'main' : function should return a value; 'void' return type assumed

  8. #8
    Registered User
    Join Date
    May 2008
    Location
    India
    Posts
    30
    Quote Originally Posted by shwetha_siddu View Post
    hai

    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(13) : error C2065: 'a' : undeclared identifier
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(13) : error C2228: left of '.year' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(15) : error C2228: left of '.month' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(16) : error C2228: left of '.starting_day' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(17) : error C2228: left of '.starting_day' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(21) : error C2228: left of '.starting_day' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\haihow\haihow.cpp(60) : warning C4508: 'main' : function should return a value; 'void' return type assumed
    That's because you haven't included the header file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  3. programm will not start
    By keeper in forum C++ Programming
    Replies: 11
    Last Post: 07-03-2006, 06:02 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21