Hi all, I have most of this code, but I\'m missing something because no matter w
ID: 3552735 • Letter: H
Question
Hi all,
I have most of this code, but I'm missing something because no matter what day of the week I input, it always comes up as "you can rest today." I know it's something in my switch statement and my call of "printf," but I just not thinking coherently. Basically if I enter Monday through Friday it should say "go to work" and if I enter Saturday & Sunday it should say "you can rest today." Thnaks for any help!!
#include <stdio.h>
enum week{ Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday};
int main()
{
enum week today;
int day;
printf("Enter a day of the week: ");
scanf("%s", &day);
switch (day)
{
case 0: day = Monday; break;
case 1: day = Tuesday; break;
case 2: day = Wednesday; break;
case 3: day = Thursday; break;
case 4: day = Friday; break;
case 5: day = Saturday; break;
case 6: day = Sunday; break;
}
if (day <5)
{
printf(" Go to work!");
}
else if (day >4)
{
printf(" You can rest today!");
}
else
return 0;
}
Explanation / Answer
#include<stdio.h>
#include<conio.h>
int main()
{
int day;
printf(" Enter day in numbers 1 to 7");
scanf("%d",&day);
switch(day)
{
case 1 :
printf(" Go to work");
break;
case 2 :
printf(" Go to work");
break;
case 3 :
printf(" Go to work");
break;
case 4 :
printf(" Go to work");
break;
case 5 :
printf(" Go to work");
break;
case 6 :
printf(" Take Rest");
break;
case 7 :
printf(" Take rest");
break;
default :
printf(" Wrong Input");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.