Answer to Question #184019 in C for Rurirururirurirurirurii

Question #184019

How to Write a c program using string functions that accepts a coded value of an item and display its equivalent tag price? Can someone enlighten me how you guys did it??


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


Note: the numbers below are the corresponding equivalent values of the letters. 



1
Expert's answer
2021-04-21T12:42:34-0400
#include <stdio.h>
#include <string.h>

#define MAX_STRING_SIZE 1024

int main()
{
    int i;
    char buffer[MAX_STRING_SIZE];

    printf("Enter coded value: ");
    fgets (buffer, MAX_STRING_SIZE, stdin);

    printf("Tag price:         ");
    
    for(i = 0; i < strlen(buffer); ++i)
    {
        switch(buffer[i])
        {
            case 'X' : printf("0"); break;
            case 'C' : printf("1"); break;
            case 'O' : printf("2"); break;
            case 'M' : printf("3"); break;
            case 'P' : printf("4"); break;
            case 'U' : printf("5"); break;
            case 'T' : printf("6"); break;
            case 'E' : printf("7"); break;
            case 'R' : printf("8"); break;
            case 'S' : printf("9"); break;
            default:   printf("%c", buffer[i]); break;
        }
    }

    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