// C08_Ex 7: Checkout cost of taxi from kilometer input. Known:
// First km: 5$
// 2 -> 5 km price: 4$
// 6 km -> price: 3$
// If > 120km , will sale 10%
#include <stdio.h>
#define G1 5
#define G2 4
#define G3 3
void main()
{
int n;
float cost;
printf("Input numbers of km (>0): ");
scanf("%d", &n);
if (n == 1)
cost = G1;
else
{
if (n >= 2 && n <= 5)
cost = G1 + (n - 1)*G2;
else
cost = G1 + 4*G2 + (n - 1 - 4)*G3;
}
if (n > 120)
cost = cost * 0.9;
printf("=> Total cost: %.2f $\n", cost);
}
// First km: 5$
// 2 -> 5 km price: 4$
// 6 km -> price: 3$
// If > 120km , will sale 10%
#include <stdio.h>
#define G1 5
#define G2 4
#define G3 3
void main()
{
int n;
float cost;
printf("Input numbers of km (>0): ");
scanf("%d", &n);
if (n == 1)
cost = G1;
else
{
if (n >= 2 && n <= 5)
cost = G1 + (n - 1)*G2;
else
cost = G1 + 4*G2 + (n - 1 - 4)*G3;
}
if (n > 120)
cost = cost * 0.9;
printf("=> Total cost: %.2f $\n", cost);
}