Hello I wrote this C program and it does not compile. it is saying \"\"\"\"due_d
ID: 3881960 • Letter: H
Question
Hello I wrote this C program and it does not compile. it is saying
""""due_date.c: In function ‘main’:
due_date.c:77: error: expected ‘)’ before ‘number_of_days’""""
this is the program
#include <stdio.h>
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;
}
Explanation / Answer
The error is with case 6
printf("%d "number_of_days+2); (Error)
printf("%d ",number_of_days+2); (Correct)
Following has no compiler errors:
#include <stdio.h>
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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.