Answer to Question #195996 in C++ for Angel

Question #195996

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


1
Expert's answer
2021-05-20T10:58:15-0400
#include <iostream>
#include <string>

int main()
{
    std::cout << "Enter a price:  ";
    std::string price;
    std::cin >> price;

    std::cout << "Coded price is: ";
    for(size_t i = 0; i < price.size(); ++i)
    {
        switch(price[i])
        {
            case '0': std::cout << 'X'; break;
            case '1': std::cout << 'C'; break;
            case '2': std::cout << 'O'; break;
            case '3': std::cout << 'M'; break;
            case '4': std::cout << 'P'; break;
            case '5': std::cout << 'U'; break;
            case '6': std::cout << 'T'; break;
            case '7': std::cout << 'E'; break;
            case '8': std::cout << 'R'; break;
            case '9': std::cout << 'S'; break;
            case '.': std::cout << '.'; break;
            default:  std::cout << "?\nError: Unexpected char\n"; return 1;
        }       
    }

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog