Hello!
I am stuck on this program I have to write for the days of the week. The days of the week is in a string array, and the program asks the user for a number between 1 and 7. The program is then supposed to spit out the corresponding day of the week. There also needs to be an error message if the user enters anything besides 1-7. This is what I got, and it keeps telling me it's Sunday no matter what I enter! Could anyone please lend me a hand to find out what is wrong here?
Code:
# include <stdio.h>
int main()
{
int day;
char *weekday[7] =
{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
printf ("Enter number between 1-7: ");
scanf ("%d", &day);
printf("\nThe day of the week is:\n\n");
if ((day=1))
{
printf("%s", weekday[0]);
}
else if ((day=2))
{
printf("%s", weekday[1]);
}
else if ((day=3))
{
printf ("%s", weekday[2]);
}
else if ((day=4))
{
printf ("%s", weekday[3]);
}
else if ((day=5))
{
printf ("%s", weekday[4]);
}
else if ((day=6))
{
printf ("%s", weekday[5]);
}
else if ((day=7))
{
printf ("%s", weekday[6]);
}
else
{
printf("Error");
}
return 0;
}
Thank you!