Write a C++ program to calculate the taxi fare using given conditions Distance in KM Cost in Rs. Per km 0 through 100 12 More than 100 but not more than 500 10 More than 500 but less than 1000 8 1000 or more 5
#include <iostream>
using namespace std;
int main()
{
float Distance;
cout << "Please, enter a distance to calculate the taxi fare: ";
cin>> Distance;
float fare;
if (Distance <= 100)
fare = Distance * 12;
else if (Distance > 100 && Distance <= 500)
fare = 100 * 12 + (Distance - 100) * 10;
else if (Distance > 500 && Distance < 1000)
fare = 100 * 12 + 400 * 10 + (Distance - 500) * 8;
else if (Distance > 1000)
fare = 100 * 12 + 400 * 10 + 500 * 8 + (Distance - 1000) * 5;
cout << "The taxi fare is " << fare;
}
Comments
Leave a comment