The code below asks for input of working hours and works out the weekly wage. The part about the longest worked day doesnt work. It gives the correct longest worked hours, but instead of the day's name it gives strange symbols. Any ideas why?
Code:
#include <stdio.h>
void main()
{
enum week{mon,tue,wed,thu,fri,sat,sun};
int hours [sun+1]; /*2D array*/
char day_name [sun+1][7] = {"mon","tue","wed","thu","fri","sat","sun"};
int rate1, rate2, wage, longest;
week day;
/*reads in student's hours*/
for(day=mon;day<=sun;day=(week)((int)(day)+1))
{
printf("\nInput the number of hours you work on mon, tue, wed, thu, fri, sat & sun\n");
for(day=mon;day<=sun;day=(week)((int)(day)+1))scanf("%d",&hours[day]);
}
printf("\nThe hours you input are:\n"
"mon = %d, tue = %d, wed = %d, thu = %d, fri = %d, sat = %d, sun = %d\n",hours[mon],
hours[tue],hours[wed],hours[thu],hours[fri],hours[sat],hours[sun]);
/*calculates the longest working day*/
longest=hours[mon];
for(day=mon;day<=sun;day=(week)((int)(day)+1))
if(longest<hours[day]) longest=hours[day];
printf("\nThe longest working day is %d hours on %s\n",longest, day_name[day]);
/*calculates money earned in a week*/
for(day=mon;day<=sun;day=(week)((int)(day)+1))
{
rate1=0;
for(day=mon;day<=fri;day=(week)((int)(day)+1))rate1=rate1+(4*hours[day]);
rate2=0;
for(day=sat;day<=sun;day=(week)((int)(day)+1))rate2=rate2+(5*hours[day]);
wage=rate1+rate2;
printf("\nThe total weekly wage is %d pounds\n\n",wage);
}
}