mercredi 22 août 2018

I don't know why I get an error in my c code (the function is not recognized in the program)

I don't know why I get an error in my c code (the function is not recognized in the program) this is a program that you input a day and outputs the next day

Now, you can return to the problem that was discovered in the previous program.Your program thinks that February always has 28 days, so naturally when you ask it for the day after February 28, it always displays March 1 as the answer.You need to make a spe- cial test for the case of a leap year. If the year is a leap year, and the month is February, the number of days in that month is 29. Otherwise, the normal lookup inside the daysPerMonth array can be made. A good way to incorporate the required changes into Program 9.2 is to develop a function called numberOfDays to determine the number of days in a month.The func- tion would perform the leap year test and the lookup inside the daysPerMonth array as required. Inside the main routine, all that has to be changed is the if statement, which compares the value of today.day to daysPerMonth[today.month - 1]. Instead, you could now compare the value of today.day to the value returned by your numberOfDays function. Study Program 9.3 carefully to determine what is being passed to the numberOfDays function as an argument.

`

 #include <stdio.h>

 _Bool isleapyear(int b){

                           int a;

                           if(b%400==0 && b%100==0)
                               a=1;
                           else if(b%4==0 && b%100!=0)
                               a=1;
                           else
                               a=0;
                           return a;
                                            }


int main(){
          struct date
         {
             int day;
             int month;
             int year;
          };
          struct date today;

printf("enter the date:");
scanf("%d %d %d", &today.day, &today.month, &today.year);

if(isleapyear(today.year)==0)
   int A[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
else
   int A[12]={31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if(today.day!=A[today.month-1])
today.day=today.day+1;
else
{   if(today.month!=12){
        today.day=1;
        today.month=today.month+1;} 
     else{
        today.day=1;
        today.month=1;
        today.year=today.year+1;}
  }

printf("The date tomorrow is: %d %d %d", today.day, today.month, today.year);
return 0;
  }

`

Aucun commentaire:

Enregistrer un commentaire