Answer to Question #332864 in C++ for Cool

Question #332864

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
2022-04-23T18:13:32-0400






#include <iostream>
#include <string>
#include  <cstdint>
#include  <cctype>
using std::cout;
using std::cin;
int main() {
 char ms[10];
  std::string d="XCOMPUTERS";
  for(size_t i=0;i<d.length();i++)
    {
      ms[i]=d[i];
    }
  std::string price;//Price
  cout<<"Enter price: ";
  cin>>price;
  cout<<"Code value: ";
  for(size_t i=0;i<price.length();i++)
    {
      if(std::isdigit(price[i]))
        cout<<ms[price[i]-'0'];
      else 
        cout<<":";
    }
  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