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
0 1 2 3 4 5 6 7 8 9
Sample Input/output Dialogue:
Enter Price: 489.50
Coded Value: PRS.UX
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Enter a price: ";
string price;
cin >> price;
cout << "Coded price is: ";
for(size_t i = 0; i < price.size(); ++i)
{
switch(price[i])
{
case '0': cout << 'X'; break;
case '1': cout << 'C'; break;
case '2': cout << 'O'; break;
case '3': cout << 'M'; break;
case '4': cout << 'P'; break;
case '5': cout << 'U'; break;
case '6': cout << 'T'; break;
case '7': cout << 'E'; break;
case '8': cout << 'R'; break;
case '9': cout << 'S'; break;
case '.': cout << '.'; break;
default: cout << "?\nError: Unexpected char\n"; return 1;
}
}
return 0;
}
Comments
Leave a comment