زبان : C -برنامه ای که با استفاده از شمارشی دستمزد کارمندی را محاسبه می کند
#include
#include
enum weekday { SAT, SUN , MON , TUE ,
WED , THU , FRI };
typedef enum weekday WEEKDAY;
WEEKDAY tomorrow(WEEKDAY);
int main ()
{
int hours ;
const float r1 = 1.2, r2 = 2.0;
float base, rate, wages = 0.0 ;
WEEKDAY day ;
clrscr();
printf("enter the basic hourly rate :") ;
scanf("%f", &base) ;
printf("enter the hours worked ");
printf("for saturday through friday:\n");
day = FRI ;
getch();
do {
day = tomorrow(day) ;
scanf("%d", &hours) ;
switch(day) {
case SAT :
case SUN :
case MON :
case TUE :
case WED :
rate = base; break ;
case THU :
rate = r1 * base; break ;
case FRI :
rate = r2 * base; break ;
}
wages += rate * hours ;
} while (day != FRI) ;
printf("\n total wages for the week is :%.2f", wages) ;
getch();
return 0;
}
//***********************
WEEKDAY tomorrow(WEEKDAY d)
{
WEEKDAY nextd ;
switch (d) {
case SUN : nextd = MON ; break ;
case MON : nextd = TUE ; break ;
case TUE : nextd = WED ; break ;
case WED : nextd = THU ; break ;
case THU : nextd = FRI ; break ;
case FRI : nextd = SAT ; break ;
case SAT : nextd = SUN ; break ;
}
return(nextd) ;
}