Question: Hello I wrote this C program and it does not compile with gcc- Wall. it is saying due_date.c: In function main: due_date.c:27: warning: implicit
Hello I wrote this C program and it does not compile with gcc- Wall. it is saying
""""
due_date.c: In function main:
due_date.c:27: warning: implicit declaration of function exit
due_date.c:27: warning: incompatible implicit declaration of built-in function exit
due_date.c:13: warning: unused variable D
due_date.c: At top level:
due_date.c:37: warning: data definition has no type or storage class
due_date.c:37: warning: type defaults to int in declaration of D
due_date.c:37: error: todays_date undeclared here (not in a function)
due_date.c:37: error: number_of_days undeclared here (not in a function)
due_date.c:39: error: expected identifier or ( before switch
due_date.c:87: error: expected identifier or ( before return
due_date.c:89: error: expected identifier or ( before } token
""""
this is the program
#include
int main ()
{
/*defining local variables*/
int todays_date;
int number_of_days;
int D;
/*Taking today's date and the number of days till due date from the user*/
printf("enter today's number 0 for sunday 1 for monday ect: ");
scanf("%d",&todays_date);
/*Checking for errors*/
{if(todays_date<0 || todays_date>6)
printf("You entered an invalid number.. try again: ");
exit(1);}
printf("enter number of days: ");
scanf("%d",&number_of_days);
}
/*Calculating days in total*/
D=(todays_date + number_of_days)%7;
switch(D)
{
case 0:printf("number of days allowed: %d ",number_of_days+1);
printf("the work is due on Monday ");
break;
case 1:printf("number of days allowed: %d ",number_of_days);
printf("the work is due on Monday ");
break;
case 2: printf("number of days allowed: %d ",number_of_days);
printf("the work is due on Tuesday ");
break;
case 3: printf("number of days allowed: %d ",number_of_days);
printf("the work is due on Wednesday ");
break;
case 4: printf("number of days allowed: %d ",number_of_days);
printf("the work is due on Thursday ");
break;
case 5: printf("number of days allowed: %d ",number_of_days+3);
printf("the work is due on Monday ");
break;
case 6: printf("%d ",number_of_days+2);
printf("the work is due on Monday ");
break;
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
