Answer to Question #310823 in C++ for Diya

Question #310823

4. A person is going on a motorway and at one point he can see roads going in three different directions. Based on the destination, he will move either toward left, right or straight. Write a C++ program that guides the traveler based on the following directions:





• If destination is Lahore, then turn left.



• If destination in Islamabad or Murree, then turn right. • Otherwise move straight.






1
Expert's answer
2022-03-13T08:09:33-0400

Here is program:

int main()
{
	int destination;
	cout << "Enter destination: " << endl;
	cout << "1)Lahore" << endl;
	cout << "2)Islamabad" << endl;
	cout << "3)Murree" << endl;
	cin >> destination;
	if (destination == 1)
	{
		cout << "Turn left" << endl;
	}
	else if (destination == 2 || destination == 3)
	{
		cout << "Turn right" << endl;
	}
	else
	{
		cout << "Move straight" << endl;
	}
}

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