Doesn't display results of the switch statement correctly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <cmath>
#include <ostream>
using namespace std;

int main()
{

cout << "\t\t\tMichael Canfield" << endl;
cout << "Phone Key Pad - Convert Letters to Numbers" << endl;
cout << "------------------------------------------" << endl;
cout << "This program will convert a phone letter' to a number" << endl;
cout << "Enter a character string phone number (###.aaa.aaaa):" << endl;

string phoneChar;
getline(cin, phoneChar);

cout << endl;


char characters[12];
for (unsigned int i = 0; i < 12; i++)
	characters[i] = phoneChar[i];
double phoneNum;

int length = 12;
for(int i=0; i < length; i++)
{

	if (isalpha(characters[i]))
	{
		switch (characters[i])
		{
		case 'A':
		case 'a':
		case 'B':
		case 'b':
		case 'C':
		case 'c':
		phoneNum = 2;
		break;

		case 'D':
		case 'd':
		case 'E':
		case 'e':
		case 'F':
		case 'f':
		phoneNum = 3;
		break;

		case 'G':
		case 'g':
		case 'H':
		case 'h':
		case 'I':
		case 'i':
		phoneNum = 4;
		break;

		case 'J':
		case 'j':
		case 'K':
		case 'k':
		case 'L':
		case 'l':
		phoneNum = 5;
		break;

		case 'M':
		case 'm':
		case 'N':
		case 'n':
		case 'O':
		case 'o':
		phoneNum = 6;
		break;

		case 'P':
		case 'p':
		case 'Q':
		case 'q':
		case 'R':
		case 'r':
		case 'S':
		case 's':
		phoneNum = 7;
		break;

		case 'T':
		case 't':
		case 'U':
		case 'u':
		case 'V':
		case 'v':
		phoneNum = 8;
		break;

		case 'W':
		case 'w':
		case 'X':
		case 'x':
		case 'Y':
		case 'y':
		case 'Z':
		case 'z':
		phoneNum = 9;
		break;
		}
		cout << phoneNum << endl;
	}

	if(i == 2)
	{
		cout << "." << endl;
	}
}

system("pause");
return 0;
}


I cannot
A: Get the program to compile at all and
B: Have the program accept both string types. 800.MIS.Dept &(800)Got-Milk

Any assistance that can be provided would be awesome. I am new to this, so go easy.

Note: This is updated code, I can now get it to compile without error, but it only accepts one input string, and outputs in a poor format, and also doesn't seem to pass the first 3 numbers that were entered along with the letters
Last edited on
Last edited on
I can tell from the format of your code and the numbers you're trying to translate that you're in my class at USF. Aren't this professor's assignments tough?!
I've altered my attempt a bunch recently. A guy is helping me out in this thread http://www.cplusplus.com/forum/beginner/45686/ if you still need help.
Topic archived. No new replies allowed.