Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.

Categories: Others. No Comments on CPP program to calculate the fare for the passengers travelling in a bus

In this article we will learn to implement a CPP program to calculate the fare for the passengers travelling in a bus. We will write a C++ Program to calculate the fare for the passengers travelling in a bus.

 

When a Passenger enters the bus, the conductor asks “What distance will you travel?” On knowing distance from passenger (as an approximate integer),
the conductor mentions the fare to the passenger according to following criteria:
5KM: Rs.10
5-10KM: Rs.20
10-30KM: Rs.50
30-50KM: Rs.100
50-80KM: Rs.150
80-100KM: Rs.250

 

Program is as follows:

#include <iostream>
using namespace std;
int main()
{
	int dist;
	cout<<"What distance will you travel? ";
	cin>>dist;
	if(dist<=5)
		cout<<"Fare is: Rs."<<10;
	else if(dist>5 && dist<10)
		cout<<"Fare is: Rs."<<20;
	else if(dist>=10 && dist<30)
		cout<<"Fare is: Rs."<<50;
	else if(dist>=30 && dist<50)
		cout<<"Fare is: Rs."<<100;
	else if(dist>=50 && dist<80)
		cout<<"Fare is: Rs."<<150;
	else if(dist>=80 && dist<=100)
		cout<<"Fare is: Rs."<<250;
	else
		cout<<"Get off bus";
	return 0;
}

 

Input and output for the above program are as follows:

What distance will you travel? 50
Fare is: Rs.150

 

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

Leave a Reply

Your email address will not be published. Required fields are marked *