#include <stdio.h>
#define t1 8.75
#define t2 9.33
#define t3 10.00
#define t4 11.20
// #define t 10 //zp
#define s 40 //sverh
#define u 1.5 //sverh*
#define n1 0.15 //tax1
#define n2 0.2
#define n3 0.25
#define m1 300 //maxbeftax2
#define m2 150

int main() {
    int h,sw,x,swt,exit,scan;
    float t,tax,a;
    exit = x = swt = scan = 1;
    while(exit){
        printf("hours: ");
        while(scanf("%d", &h)!=1){
            printf("input err\n");
            if(getchar() == EOF) return 0; 
            while (getchar() != '\n') continue; 
            printf("hours: ");
        }
        while (getchar() != '\n') continue;
        do{
                while (getchar() != '\n') continue; 
                printf("Choose tarif:\n");
                printf("a) $%.2f/h\tb) $%.2f/h\n",t1,t2);
                printf("c) $%.2f/h\td) $%.2f/h\n",t3,t4);
                printf("q) exit\nInput: ");
                sw = getchar();
                if(getchar() == EOF){return 0;}
				while (getchar() != '\n') continue;
                switch(sw){
                    case 'a': t = t1; swt = 0; break;
                    case 'b': t = t2; swt = 0; break;
                    case 'c': t = t3; swt = 0; break;
                    case 'd': t = t4; swt = 0; break;
                    case 'q': exit = 0; break; 
                    default: printf("input err\n");
                }
            }while(swt&&exit);

        if(!swt && exit){
            if (h>s){tax = a = (s*t + ((h-s) * (t*u)));}
            else(tax = a = h*t);  

            if (tax>m1)
            {
                if(tax>m2){tax = (m1*n1) + (m2*n2) + ((tax-m1-m2)*n3);}
                else(tax = (m1*n1) + ((tax-m1)*n2));
            }
            else (tax*=n1);
            printf("Acc: %.3f\nTax: %.3f\nReceived: %.3f\n",a,tax,a-tax);
        }} 

  return 0;
}
