Answer to Question #337937 in C++ for MARTY

Question #337937

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


1
Expert's answer
2022-05-08T14:33:13-0400
#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;
}

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
APPROVED BY CLIENTS