alpha phone number to phone number

I posted earlier about a code I created that converts Alpha Phone numbers into numeric ones. It turns out that doesn’t work very well. It messes up at 789.

Here is the updated version

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

int main(void)
{
char ch;
int storing;

printf(“Enter phone number: “);

while ((ch = getchar()) != ‘\n’)
{

if (ch >= ‘A’ && ch <= ‘R’)
{
storing = ((ch – ‘A’) / 3)+2;
printf(“%d”, storing);
}
else if (ch >= ‘S’ && ch <= ‘Y’)
{
storing = ((ch – ‘A’)-1) / 3 + 2;
printf(“%d”, storing);
}
else if (ch == ‘-‘)
{
printf(“%c”, ch);
}
else if((ch>=’0′ && ch<=’9’))
{
storing= ch – ‘0’;
printf(“%d”, storing);
}

// putchar(ch);

}
system(“pause”);
return 0;
}

Alphabetic Phone Number to Numeric Phone Number code

I wrote this code in C a couple months ago. It converts Alpha phone numbers to numeric phone numbers.

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

int main(void)
{
	char ch;
	int storing; 
	

	printf("Enter phone number: ");

	while ((ch = getchar()) != '\n') 
	{
		
		storing = (ch - 'A')/3+2;

		if (ch == 'Y' || ch == 'S' || ch=='Z')
		{
			storing = storing - 1;
		}

		printf("%d", storing); 
	
	//	putchar(ch);
		
	}
	system("pause"); 
	return 0;
}

Please note I wrote this in Visual Studio. 

Technology Amateur

Hi, I am a technology enthusiast. I code, build robots, and I like to hack tech products. In this blog, I will be writing about things I have coded, and tech products. I have a passion for photography, and will periodically post some of my pictures too. I enjoy traveling and have visited various countries and cities. I especially like beach vacations. I also play golf.