If and While Preceeding Switch Statements and Clashing

I hope you can see what I am trying to do using my comments) the statements/commands are clashing into each other and no matter how I have tweaked things and changed brackets around, something always clashes into the other.

Psuedocode:

Prompt user to enter a letter that corresponds to a digit on the phone.

Input user’s choice.

Use do-while so when the user enters anything other than $, the program will run. $ will terminate the program.

If the user enters a lower case letter, prompt the user that the letter is lower case and then convert it to uppercase and print out the corresponding number.

Use while for user enters a q, Q, z, or Z prompt that those letters are not on the phone and allow them to reenter a new choice until they enter something valid. Also, negate the output for the lower to uppercase letter conversion to the user

If the user enters a special character, prompt that the program will not accept these and allow them to reenter a new choice until they enter something valid.


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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <iostream>
#include <cctype>//using this library for toupper conversion

using namespace std;
int main()

{
	char choice;
	char VIEW = '$';//declare $

	do//begin do-while that will run the program for any choice input except $ which should terminate the program

	{
		cout << endl

			<< "Enter A, B, or C for digit 2\n"
			<< "Enter D, E, or F for digit 3\n"
			<< "Enter G, H, or I for digit 4\n"
			<< "Enter J, K, or L for digit 5\n"
			<< "Enter M, N, or O for digit 6\n"
			<< "Enter P, R, or S for digit 7\n"
			<< "Enter T, U, or V for digit 8\n"
			<< "Enter W, X, or Y for digit 9\n";
	
		cin >> choice;//user inputs a character

		//command to convert any upper case letters to lowercase
		{
			cout << "You entered a lowercase letter and now I will convert it to uppercase for you.\n";
			cout << (char)toupper(choice);//if the choice is a lowercase letter, convert to uppercase
		}
		
		//command to prompt user to enter a new choice if they enter these characters until they enter something valid
		while (choice == 'q' || choice == 'Q' || choice == 'z' || choice == 'Z')//while the user enters any of these chars, they will be prompted to re-enter a new choice until they enter something valid
		{
			!((char)toupper(choice));//negate output that letter will be made uppercase
			cout << "No digit corresponds to" << choice << endl;
			cout << "Enter a new letter";
			cin >> choice;
		}	
	
		//begin switch statement for valid choice entries
		switch (choice)
		{

		case 'A':
			cout << "2" << endl;
			break;

		case 'B':
			cout << "2" << endl;
			break;

		case 'C':
			cout << "2" << endl;
			break;

		case 'D':
			cout << "3" << endl;
			break;

		case 'E':
			cout << "3" << endl;
			break;

		case 'F':
			cout << "3" << endl;
			break;

		case 'G':
			cout << "4" << endl;
			break;

		case 'H':
			cout << "4" << endl;
			break;

		case 'I':
			cout << "4" << endl;
			break;

		case 'J':
			cout << "5" << endl;
			break;

		case 'K':
			cout << "5" << endl;
			break;

		case 'L':
			cout << "5" << endl;
			break;

		case 'M':
			cout << "6" << endl;
			break;

		case 'N':
			cout << "6" << endl;
			break;

		case '0':
			cout << "6" << endl;
			break;

		case 'P':
			cout << "7" << endl;
			break;

		case 'R':
			cout << "7" << endl;
			break;

		case 'S':
			cout << "7" << endl;
			break;

		case 'T':
			cout << "8" << endl;
			break;

		case 'U':
			cout << "8" << endl;
			break;

		case 'V':
			cout << "8" << endl;
			break;

		case 'W':
			cout << "9" << endl;
			break;

		case 'X':
			cout << "9" << endl;
			break;

		case 'Y':
			cout << "9" << endl;
			break;

		case '$':
			cout << "The $ terminates this program" << endl;//tells user the program will terminate
			break;
		
		//default for special characters
		default:
			cout << "Not a valid choice, which means you entered a special character or number. Re-enter a choice.\n";

		}
	} while (choice != '$');//close do-while that will run the program for any choice input except $ which should terminate the program
	return 0;
}
Well, what you can do is break the comments into two lines- make it so that half of it (or more) carries over in the same indentation: like this:
1
2
3
4
5
6
7
8
//command to prompt user to enter a new choice if they enter these characters until they enter something valid
		while (choice == 'q' || choice == 'Q' || choice == 'z' || choice == 'Z')//while the user enters any of these chars...
		{
			!((char)toupper(choice));                                       //negate output that letter will be made uppercase
			cout << "No digit corresponds to" << choice << endl;            //they will be prompted to re-enter a new choice until they enter something valid
			cout << "Enter a new letter";
			cin >> choice;
		}	


Also, you can break those massive while-based truth testing for user input into multiple lines- whitespace means nothing except in strings and template-templates, after all.
Last edited on
I figured things out, Thanks for the help!
Topic archived. No new replies allowed.