# Lab 5
## Lab 5-1.c
```cpp=
/* I1B31 羅崧瑋 */
#include <stdio.h>
int main(void) {
float gallons=0;
float miles=0;
while(gallons!=-1){
printf("Enter the gallons used(-1 to end): ");
scanf("%f",&gallons);
if(gallons==-1) break;
printf("Enter the miles driven: ");
scanf("%f",&miles);
printf("The miles/gallons for this tank was %lf\n\n",miles/gallons);
}
return 0;
}
```
## Lab 5-2.c
```cpp=
/* I1B31 羅崧瑋 */
#include <stdio.h>
int main(void) {
float dollars=0;
while(dollars!=-1){
printf("Enter sales in dollars(-1 to end): ");
scanf("%f",&dollars);
if(dollars==-1) break;
printf("Salary is: %.2lf\n\n",200+(dollars*0.09));
}
return 0;
}
```
## Lab 5-3.c
```cpp=
/* I1B31 羅崧瑋 */
#include <stdio.h>
int main(void) {
int payCode=0;
double Salary;
double hour=0;
int piece;
int m_count=0; /* Manager */
int h_count=0; /* Hourly */
int c_count=0; /* Commision */
int p_count=0; /* piece */
while(payCode!=-1){
printf("Enter pay code(-1 to end): ");
scanf("%d",&payCode);
if(payCode==-1) break;
switch(payCode){
case 1:
printf("Manager selected.\n");
printf("Enter the weekly salary: ");
scanf("%lf",&Salary);
printf("The manager's pay is $%.2lf\n\n",Salary);
m_count++;
break;
case 2:
printf("Hourly worker selected.\n");
printf("Enter the hourly salary: ");
scanf("%lf",&Salary);
printf("Enter the total hours worked: ");
scanf("%lf",&hour);
if(hour>40) printf("Worker worked %.1lf overtimes hours.\n",hour-40);
printf("Worker's pay is $%.2lf\n\n",Salary*40+Salary*(hour-40)*1.5);
h_count++;
break;
case 3:
printf("Commision worker selected.\n");
printf("Enter the gross weekly sales: ");
scanf("%lf",&Salary);
printf("Commision's pay is $%.2lf\n\n",250+Salary*0.057);
c_count++;
break;
case 4:
printf("Pieceworker selected.\n");
printf("Enter the number of piece: ");
scanf("%d",&piece);
printf("Enter the wage per piece: ");
scanf("%lf",&Salary);
printf("Pieceworker's pay is $%.2lf\n\n",Salary*piece);
p_count++;
break;
default:
printf("Invalid pay code.\n\n");
break;
}
}
printf("\nTotal number of managers paid :%d\n",m_count);
printf("Total number of hourly workers paid :%d\n",h_count);
printf("Total number of commission workers paid :%d\n",c_count);
printf("Total number of pieceworkers paid :%d\n",p_count);
return 0;
}
```
## Lab 5-4.c
有人偷渡 leetcode ( x
```cpp=
/* I1B31 羅崧瑋 */
#include <stdio.h>
int main(void) {
int dec;
/* I IV V IX X XL L XC C */
/* 1 4 5 9 10 40 50 90 100*/
int r[9]={1,4,5,9,10,40,50,90,100};
char *c[9]={"I","IV","V","IX","X","XL","L","XC","C"};
char *result;
printf("Input a decimal number (1~100): ")
scanf("%d",&dec);
for(int i=8;i>=0;i--) {
while(dec>=r[i]) {
printf("%s",c[i]);
dec-=r[i];
}
}
return 0;
}
```