Question
Hello I wrote this C program but it is not compiling with gcc -Wall .. it is giving the error due_date.c: In function main:
Hello I wrote this C program but it is not compiling with gcc -Wall .. it is giving the error """"
due_date.c: In function main:
due_date.c:14: warning: implicit declaration of function exit
due_date.c:14: warning: incompatible implicit declaration of built-in function exit
"""
The reason I am using exit is because I have to abort the program if a condition is not met "If the entered day for today is not in the range of 0 to 6, display an error message and abort the program. "
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started