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”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter first character: ");
string c = Console.ReadLine().ToLower();
switch (c)
{
case "b": Console.WriteLine("Blue");
break;
case "r":
Console.WriteLine("Red");
break;
case "g":
Console.WriteLine("Green");
break;
case "y":
Console.WriteLine("Yellow");
break;
default:
Console.WriteLine("Unknown Color");
break;
}
Console.ReadKey();
}
}
}
Comments
Leave a comment