6.1.
Write a program using standard string functions that accepts a price of an item and display its coded value.
The base of the key is: X C O M P U T E R S 1 2 3 4 5 6 7 8 9
Sample input/output dialogue: Enter price: 489.50
Coded value: PRS.UX
internal class Program
{
static void Main()
{
Console.Write("Enter price: ");
string price = Console.ReadLine();
string code = "";
for (int i = 0; i < price.Length ; i++)
{
if (price[i] == '0')
code += "X";
else if (price[i] == '1')
code += "C";
else if (price[i] == '2')
code += "O";
else if (price[i] == '3')
code += "M";
else if (price[i] == '4')
code += "P";
else if (price[i] == '5')
code += "U";
else if (price[i] == '6')
code += "T";
else if (price[i] == '7')
code += "E";
else if (price[i] == '8')
code += "R";
else if (price[i] == '9')
code += "S";
else if (price[i] == '.')
code += ".";
}
Console.WriteLine($"Coded value: {code}");
Console.ReadKey();
}
}
Comments
Leave a comment