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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q180350
{
class Program
{
static void Main(string[] args)
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-us");
string codedValues = "XCOMPUTERS";
Console.Write("Enter price: ");
//read price
string price = Console.ReadLine();
string codedValue="";
double dblPrice=0;
try
{
if (double.TryParse(price, out dblPrice))
{
///convert price to the coded value
for (int i = 0; i < price.Length; i++)
{
if (price[i] != '.')
{
codedValue += codedValues[int.Parse(price[i].ToString())].ToString();
}
else
{
codedValue += ".";
}
}
//display the coded value
Console.WriteLine("Coded value: {0}", codedValue);
}
else
{
Console.WriteLine("Wrong price.");
}
}
catch (Exception ex) {
Console.WriteLine("Wrong price.");
}
Console.ReadLine();
}
}
}
Comments
Leave a comment