C Programming : C Programming Code 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

Accept the number in km

Check the number positive or negative

If the number is negative, display error massage as km can't be negative number else continue

Calculate the fare based on the given criteria

       Display the output

Code

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int km;
float fare;
printf("Enter the distance in km\n"wink;
scanf("%d",&km);
if(km<0)
printf("Distance can not be negative. Please enter non negative no"wink;
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();
}
Posted by makeale 01/05/2015 03:05 PM Comments
 

Archives