I have a programming assignment where the user selects from pre-defined choices for a day of the week (S-Sunday, R-Thursday, A-Saturday, etc.) and then if it is a weekend, it prints back it's the weekend, if a week day and between 8-17 (8AM - 5PM) it says at work, and if before 8AM, it says asleep, then anything else is off work. It will also display the total number of times for errors, weekends, sleep, etc, but I haven't added that in yet as I'm having problems with the primary function. It works fine for the first two selections (Max of 5 correct selections before it terminates) then after that it goes to the default else of invalid day, even if I go back and type in one that worked previously. I've tried numerous reworkings so far, but if anyone sees a error, and can fix this, I would greatly appreciate it.
Code:
// Program Two CSE 1030 Alexander Hollis email csp01
#define OUTPUT printf
#include <stdio.h>
int main() {
char choice[2+1];
int STOP=0;
int count=0,hour,weekends=0,
weekdays=0,invalidD=0,atwork=0,
asleep=0,offwork=0,invalidH=0;
OUTPUT("Program Two CSE 1030 Alexander Hollis email csp01\n\n");
while(count <5) {
OUTPUT("Enter day of week (S M T W R F A): ");
choice[0]=getchar();
choice[1]=getchar();
printf("You selected: %c",&choice[0]);
if(choice[0] == 'S' || choice[0]=='A')
{
OUTPUT("\nIt's the weekend!\n");
weekends++;
count++;
}
else
{
if(choice[0]=='M' || choice[0]=='T' || choice[0]=='W' || choice[0]=='R' || choice[0]=='F')
{
while(STOP == 0)
{
OUTPUT("Enter hour (0-23): ");
scanf("%d",&hour);
if(hour >= 0 && hour <=23)
{
if(hour >=8 && hour <=17)
{
OUTPUT("\nShould be at work.\n");
atwork++;
}
else
if(hour >= 0 && hour < 8)
{
OUTPUT("\nStill Asleep.\n");
asleep++;
}
else
{
OUTPUT("\nOff Work\n");
offwork++;
}
count++;
STOP =1;
}
else
{
OUTPUT("\nInvalid hour entered. Try Again.\n");
invalidH++;
}
}
weekdays++;
}
else if(choice[0] !='S' || choice[0] !='A')
{
OUTPUT("Invalid Day!\n");
invalidD++;
}
}
fflush(stdin);
}
return 0;
}