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
#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;
}
Comments
Leave a comment