6.2.
Write a program using string functions that accepts a coded value of an item and display its equivalent tag price.
The base of the key is: 0 1 2 3 4 5 6 7 8 9 -‐-‐-‐-‐-‐
X C O M P U T E R S
Sample input/output dialogue: Enter coded value: TR.XX
Tag price: 68.00
using System;
namespace tag_price
{
class Program
{
public static void Main(string[] args)
{
string str, rez;
double tag_price;
int i, j, flag;
int[] key1 = new int [10] {0, 1, 2, 3, 4 ,5, 6, 7, 8, 9};
char[] key2 = new char[10] {'X', 'C', 'O', 'M', 'P', 'U', 'T', 'E', 'R', 'S'};
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Console.Write("Enter coded value: ");
str = Console.ReadLine();
rez = "";
for (i=0; i<str.Length; i++)
{
flag = 0;
for (j=0; j<10; j++)
if (str[i] == key2[j])
{
flag = 1;
rez = rez+ key1[j];
}
if (flag == 0)
rez = rez + str[i];
}
tag_price = Convert.ToDouble(rez);
Console.WriteLine("Tag price: {0:f2}", tag_price);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Comments
Leave a comment