954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Phone output

//Enter phone number: 1-800-COL-LECT
//1-800-265-5328
Im trying to input the dash right after COL and before LECT. Please help

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	char ch;
	printf("Enter Phrase\n");
	
	while((ch=getchar())!='\n')
		
	{
		if ((ch=='1'))
			printf("1-800-");
		
		else if((ch=='A')||(ch=='B')||(ch=='C'))
			printf("2");
		
		else if ((ch=='D')||(ch=='E')||(ch=='F'))
			printf("3");
		
		else if ((ch=='G')||(ch=='H')||(ch=='I'))
			printf("4");
		
		else if ((ch=='J')||(ch=='K')||(ch=='L'))
			printf("5");
		
		else if ((ch=='M')||(ch=='N')||(ch=='O'))
			printf("6");
		
		else if((ch=='P')||(ch=='Q')||(ch=='R')||(ch=='S'))
			printf("7");
		
		else if((ch=='T')||(ch=='U')||(ch=='V'))
			printf("8");
		
		else if((ch=='W')||(ch=='X')||(ch=='Y')||(ch=='Z'))
			printf("9");
	
	}
	
	
	return 0;
}

//Enter phone number: 1-800-COL-LECT
//1-800-265-5328

alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 

Hello alex1050,
Try giving if-else statement for '-' also. I think then it would work.

Arbus
Practically a Master Poster
615 posts since Dec 2010
Reputation Points: 45
Solved Threads: 31
 

Not really a question?? Explain what u want properly.. The code above shows me nothing except that you have it set up like a telephone thats all.. and it prints a corresponding number when the person types a letter..

What exactly do u want?

you can do something like after the first character is pressed, printf("-") then after 3 characters is pressed do the same and then another three

triumphost
Posting Whiz
390 posts since Oct 2009
Reputation Points: 57
Solved Threads: 36
 

Not really a question?? Explain what u want properly.. The code above shows me nothing except that you have it set up like a telephone thats all.. and it prints a corresponding number when the person types a letter..

What exactly do u want?

you can do something like after the first character is pressed, printf("-") then after 3 characters is pressed do the same and then another three

yeah triumphost thats what im trying to do...how can i achieve this?

alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 
yeah triumphost thats what im trying to do...how can i achieve this?


Youare allowed to read more than just the last post. Arbus gave you the solution.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 
You are allowed to read more than just the last post. Arbus gave you the solution.


Walt im kind of confused to executed this can you help please. thanks

alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 
Hello alex1050, Try giving if-else statement for '-' also. I think then it would work.


Alright thanks Arbus

alex1050
Newbie Poster
24 posts since Mar 2011
Reputation Points: 6
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: