Answer to Question #297973 in C++ for niel tisoy

Question #297973

Write an algorithm that displays an equivalent color once an input letter matches its first character.




For example b for Blue, r for Red, and so on. Here are the given criteria: (The letters as an input data and the color as output information).




Letters Color




‘B’ or ‘b’ Blue




‘R’ or ‘r’ Red




‘G’ or ‘g’ Green




‘Y’ or ‘y’ Yellow




Other letters “Unknown Color”


1
Expert's answer
2022-02-15T09:53:24-0500


#include <iostream>
#include <string>


using namespace std;


int main()
{
	char color;
	cout<<"Select color: ";
	cin>>color;
	switch(color){
	case 'b':
	case 'B':
		cout<<"Blue\n\n";
		break;
	case 'r':
	case 'R':
		cout<<"Red\n\n";
		break;
	case 'g':
	case 'G':
		cout<<"Green\n\n";
		break;
	case 'y':
	case 'Y':
		cout<<"Yellow\n\n";
		break;
	default:
		cout<<"Unknown Color\n\n";
		break;


	}
	system("pause");
	return 0;
}

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