I need the CORRECT answers for these two questions that are

I need the CORRECT answers for these two questions that are based on the Code provided below. Im posting the description for the code and the code itself. PLEASE answer BOTH of the questions CORRECTLY. Let me know if you have any questions. Thank you. I just need the answer to both of the questions, it can be short sentence summary if you want but it has to be complete and correct.

I posted this question before too but got spammed heres the link to it:

https://www.chegg.com/homework-help/questions-and-answers/need-correct-answers-two-questions-based-code-provided--im-posting-description-code-code---q18919966

Questions: (1) What changes you need to make to the program that will also allow the user to enter the name of the month and a 4-digit integer for a year and display this information together with the one-month calendar? (2) What changes you need to make to the program that will let the user to just enter valid integers for the month and the year and display the correct one-month calendar?

Solution

Answer for part 1:

-------------------------------------------------------------------------------

#include <stdio.h>
#include<string.h>


int main()
{
   int i,numOfDays,startDay;
   int flag=0;
   int repeat=1;
   char monthName[4] = { \'\\0\' };
   int year;
  
   do
   {
        do
        {
            printf(\"\ Enter name of month[Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec]: \");
            scanf(\"%s\",monthName);
          
            if (!strcmp(monthName,\"Jan\") &&
                !strcmp(monthName,\"Feb\") &&
                !strcmp(monthName,\"Mar\") &&
                !strcmp(monthName,\"Apr\") &&
                !strcmp(monthName,\"May\") &&
                !strcmp(monthName,\"Jun\") &&
                !strcmp(monthName,\"Jul\") &&
                !strcmp(monthName,\"Aug\") &&
                !strcmp(monthName,\"Sep\") &&
                !strcmp(monthName,\"Oct\") &&
                !strcmp(monthName,\"Nov\") &&
                !strcmp(monthName,\"Dec\"))
            {
                    printf(\"\ Wrong input for the name of month\ \");
                    flag = 0;
            }
            else
            {
                flag=1;
            }
       }while(flag==0);
     
       printf(\"Enter the year:\");
       scanf(\"%d\",&year);
     
       flag=0;
        do
        {
            printf(\"\ Enter number of days in month: \");
            scanf(\"%d\",&numOfDays);
          
            if (numOfDays<28 || numOfDays>31)
            {
                if (numOfDays == 0)
                {
                    break;
                }
                else
                {
                    printf(\"\ Wrong input for the number of days\ \");
                    flag = 0;
                }
            }
            else
            {
                flag=1;
            }
       }while(flag==0);
          
       flag = 0;
       if (numOfDays!=0)
       {
           do
           {
                printf(\"\ Enter starting day of the week(1=Sun,7=Sat: \");
                scanf(\"%d\",&startDay);
                  
                if (startDay<0 || startDay>7)
                {
                   printf(\"\ Wrong input for starting day\ \");
                    flag=0;
                }
                else
               {
                    flag=1;
                }
           }while(flag==0);
          
            printf (\"\ Month: %s, Year: %d\ \",monthName,year);  
            printf (\"\ Sun\\tMon\\tTue\\tWed\\tThu\\tFri\\tSat\ \ \");
            for(i=1;i<=numOfDays+startDay-1;i++)
            {
                 if(i<startDay)
                {
                    printf(\"\\t\");
                 }
                else
               {
                    printf(\"%d\\t\",i-startDay+1);
                }
               if (i%7==0)
                    printf(\"\ \");
                      
                  
            }
            printf(\"\ \");
        }
        else
        {
            repeat = 0;
        }
   }while(repeat);
      
   printf(\"\ ***Program Terminated ***\ \");
   return 0;
}

----------------------------------------------------------------------------------

Answer for part 2:

-----------------------------------------------

#include <stdio.h>


int main()
{
   int i,numOfDays,startDay;
   int flag=0;
   int repeat=1;
   int month;
   int year;
  
   do
   {
        do
        {
            printf(\"\ Enter name of month[1=Jan,2=Feb,...12=Dec]: \");
            scanf(\"%d\",&month);
          
            if (month < 1 || month > 12)
            {
                    printf(\"\ Wrong input of month\ \");
                    flag = 0;
            }
            else
            {
                flag=1;
            }
       }while(flag==0);
     
       printf(\"Enter the year:\");
       scanf(\"%d\",&year);
     
       flag=0;
        do
        {
            printf(\"\ Enter number of days in month: \");
            scanf(\"%d\",&numOfDays);
          
            if (numOfDays<28 || numOfDays>31)
            {
                if (numOfDays == 0)
                {
                    break;
                }
                else
                {
                    printf(\"\ Wrong input for the number of days\ \");
                    flag = 0;
                }
            }
            else
            {
                flag=1;
            }
       }while(flag==0);
          
       flag = 0;
       if (numOfDays!=0)
       {
           do
           {
                printf(\"\ Enter starting day of the week(1=Sun,7=Sat: \");
                scanf(\"%d\",&startDay);
                  
                if (startDay<0 || startDay>7)
                {
                   printf(\"\ Wrong input for starting day\ \");
                    flag=0;
                }
                else
               {
                    flag=1;
                }
           }while(flag==0);
          
            printf (\"\ Month: %d, Year: %d\ \",month,year);  
            printf (\"\ Sun\\tMon\\tTue\\tWed\\tThu\\tFri\\tSat\ \ \");
            for(i=1;i<=numOfDays+startDay-1;i++)
            {
                 if(i<startDay)
                {
                    printf(\"\\t\");
                 }
                else
               {
                    printf(\"%d\\t\",i-startDay+1);
                }
               if (i%7==0)
                    printf(\"\ \");
                      
                  
            }
            printf(\"\ \");
        }
        else
        {
            repeat = 0;
        }
   }while(repeat);
      
   printf(\"\ ***Program Terminated ***\ \");
   return 0;
}

I need the CORRECT answers for these two questions that are based on the Code provided below. Im posting the description for the code and the code itself. PLEAS
I need the CORRECT answers for these two questions that are based on the Code provided below. Im posting the description for the code and the code itself. PLEAS
I need the CORRECT answers for these two questions that are based on the Code provided below. Im posting the description for the code and the code itself. PLEAS
I need the CORRECT answers for these two questions that are based on the Code provided below. Im posting the description for the code and the code itself. PLEAS

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site