# C Programming for Fare Calculation

C Programming for Fare Calculation for the following criteria
For 1 to 3 km, the fare is 2 dollar fixed
For >3 km, the fare is 0.5 dollar per km
Algorithm

1. Accept the number in km
2. Check the number positive or negative
3. If the number is negative, display error massage as km can’t be negative number else continue
4. Calculate the fare based on the given criteria
5. Display the output

Code
```#include<stdio.h> #include<conio.h> void main() { clrscr(); int km; float fare; printf("Enter the distance in km\n"); scanf("%d",&km); if(km<0) printf("Distance can not be negative. Please enter non negative no"); else { if(km>=1 && km<=3) fare=2; else fare=2+(km-3)*0.5; printf("\n Distance: %d km",km); printf(" \n Fare= %f dollar",fare); } getch(); }```

Previous Post: C Programming code to calculate area of a circle

October 1, 2014 - In

Next Post: Real Sequences – Applied Mathematics I

October 3, 2014 - In Mathematics

### Related Posts

#### Matlab Code for Computer Exercise C8.6 Monson H. Hayes Statistical DSP

• October 1, 2014