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”
#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;
}
Comments
Leave a comment