In: Computer Science
A program written in C that asks for the distance to be entered and then prints the fare
A transportation company has the following rates
Write a program that asks for the distance to be entered and then prints the fare
Check your answers 50 miles
should cost $10
150 miles should cost $25
300 miles should cost $38
CODE :
OUTPUT :
Raw_Code :
#include<stdio.h>
//including standard library
int main(){
int miles;
float cents,dollors;
//declaring required variables
printf("Enter Number of Miles : ");
scanf("%d",&miles);
//taking miles as input
if(miles<=100){
//if it is
first 100 miles
cents = miles * 20;
}
else if(miles > 100 && miles <=
200){ //if it is less than 200
miles
cents = (100 * 20) + ((miles - 100)
* 10);
}
else if(miles > 200 && miles <=
300){ //if it is
less than 300 miles
cents = (100 * 20) + (100 * 10) +
((miles - 200) * 8);
}
else if(miles > 300){
//if it is greater than 300
miles
cents = (100 * 20) + (100 * 10) +
(100 * 8) + ((miles - 300) * 5);
}
dollors = cents / 100;
//converting cents to dollors
printf("The Transport Fare for %d miles is :
$%.2f\n",miles,dollors); //printing
required output
return 0;
}
**********Comment me for any Queries and Rate me up*************