I am trying to convert a set of letters into a 7 digit phone number with a "-" after the third digit. The function needs to allow the user to enter more than 7 letters and then allow them to enter another phone number. So far this is what I have.
#include <iostream>
using namespace std;
int main()
{
char letter;
int digit, num;
cout << "Program to convert letters to "
<< "corresponding phone numbers."
<< endl;
cout << "Enter # to stop the program." << endl;
cout << "Enter phone number using letters: ";
cin >> letter;
cout << endl;
while (letter != '#')
{
cout << "Phone number = ";
num = static_cast<int>(letter)
- static_cast<int>('a'),('A');
if (0 <= num && num < 26)
{
digit = (num / 3) + 2;
if (((num / 3 == 6) || (num / 3 == 7)) && (num % 3 == 0))
digit = digit - 1;
if (digit > 9)
digit = 9;
cout << digit << endl;
}
cout << "\nEnter another number." << endl;
cin >> letter;
cout << endl;
}
system("pause");
return 0;
}
When I enter "Get Loan" my result is this
Program to convert letters to corresponding phone numbers. Enter # to stop the program. Enter phone number using letters: Get Loan
Phone number =
Enter another number.
Phone number = 3
Enter another number.
Phone number = 8
Enter another number.
Phone number =
Enter another number.
Phone number = 6
Enter another number.
Phone number = 2
Enter another number.
Phone number = 6
Enter another number.
It is skipping the uppercase letters and not stringing the number together. I have tried to use a for loop which added a count up to 7 and then added a "-" when the count reached 3. but that had even worse results.