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