create a program that will ask the users to input a price of the item and will display its coded value as
c o m p u t e r c y
0 1 2 3 4 5 6 7 8 9
for exam the output is:
enter the price of the item: 123.4
the coded price is: omp.u
1
Expert's answer
2014-08-14T11:49:58-0400
#include <stdio.h> #include <stdlib.h> //main function int main(){
char code[]={'c','o','m','p','u','t','e','r','c','y'}; char price[20]; //prompt user the price of the item printf("Enter the price of the item: "); //read price scanf("%s",&price); //display the coded price is: int i=0; printf("The coded price is: "); while(price[i]!='\0'){ int number =price[i] - '0'; if(number>=0 && number<10){ //show code printf("%c",code[number]); }else{ //show . or other symbol printf("%c",price[i]); } //increment i i++; }
Comments