-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrent.c
90 lines (77 loc) · 1.43 KB
/
rent.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
#include <assert.h>
#include <stdbool.h>
double payableAmount(char vehicleType , int numDays)
{
double rent,amount,discount;
switch (vehicleType)
{
case 'a':
rent = 4000;
break;
case 'b':
rent = 8000;
break;
}
if (numDays >= 3 && numDays <= 5 )
discount = 0.1;
else if (numDays >= 6)
discount = 0.2;
rent *= numDays;
amount = rent - rent * discount;
return amount;
}
double paymentAfterTax(double payment)
{
double rate;
if (payment > 15000)
rate = 0.2;
else if (payment <= 15000 && payment > 10000)
rate = 0.1;
else if (payment < 10000)
rate = 0.05;
payment += payment * rate;
return payment;
}
void testPaymentAfterTax()
{
assert(paymentAfterTax(18000) == 21600.00);
assert(paymentAfterTax(13000) == 14300.00);
assert(paymentAfterTax(5000) == 5250.00);
}
int main(void)
{
char type;
int numDays;
double payment;
bool valid;
testPaymentAfterTax();
do
{
valid = true;
printf("Vehicle Type : ");
if (scanf(" %c",&type)!=1 || (type != 'a' && type != 'b'))
{
printf("Invalid Input !!\n");
while(getchar()!='\n');
valid = false;
}
}while(!valid);
do
{
valid = true;
printf("Num.of.Days :");
if (scanf("%i",&numDays)!=1)
{
printf("Invalid Input !!\n");
while(getchar()!='\n');
valid = false;
}
}while(!valid);
if(valid)
{
payment = paymentAfterTax (payableAmount(type,numDays));
printf("Payment : %.2f",payment);
}
return 0;
}