Answer to Question #182319 in C for jhon

Question #182319

Write a program using standard string functions that accepts a price of an item  and display its coded value and tag price (vice versa). The base of the key is:

C O M E A N D B U Y 

1 2 3 4 5 6 7 8 9 0




1
Expert's answer
2021-04-18T05:31:30-0400
#include <stdio.h>
#include <stdlib.h>


int main()
{
    int iPrice;
    int size;
    printf("Enter the number of digits in price: ");
    scanf("%d", &size);
    char cPrice[size];
    printf("Write a price: ");
    scanf("%d", &iPrice);
    sprintf(cPrice, "%d", iPrice);
    int i;
    for(i = 0; i < sizeof(cPrice); ++i)
    {
        if(cPrice[i] == '0')
            printf(" Y");
        else if(cPrice[i] == '1')
            printf(" C");
        else if(cPrice[i] == '2')
            printf(" O");
        else if(cPrice[i] == '3')
            printf(" M");
        else if(cPrice[i] == '4')
            printf(" E");
        else if(cPrice[i] == '5')
            printf(" A");
        else if(cPrice[i] == '6')
            printf(" N");
        else if(cPrice[i] == '7')
            printf(" D");
        else if(cPrice[i] == '8')
            printf(" B");
        else if(cPrice[i] == '9')
            printf(" U");
    }
    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