Answer to Question #314389 in C++ for wania

Question #314389

 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



1
Expert's answer
2022-03-19T12:25:12-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog