Answer to Question #44884 in C for marinel dalangay

Question #44884
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
Expert's answer
#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++;
}

system("PAUSE");//delay
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 first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal