How do I put in a yes or no input statement? Yes for the program to run and no for the program to stop

How do I put in a yes or no input statement? Yes for the program to run and no for the program to stop. I also need a yes or no input at the end of the program as well but I still to be getting errors such as "Expected instalizers before 'swtich' on the switch statement. Basically I am trying to prompt the user two times, first before the program executes the main code and after the first iteration of code asking the user if he would like to run the program again.
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
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int LettertoNumber (char);

int main()
{
cout <<"-------------------------------------------------------" <<endl;
cout <<"Ani Biswas	CSC133-01	Lab02.cpp	09/27/16" <<endl;
cout <<"-------------------------------------------------------" <<endl;

//Declaration of variables
char PhoneNumber[11];
//Beginning of main program
	cout<<"This program converts letters to their corresponding telephone digits" <<endl;
{
	string input;
	cout<<"Input y to start the program and input n to end the program" <<endl;
	cin>> input;
	if(input.compare("y"))
	{
	cout<<"Enter a phone number: " <<endl;
	cin.getline( PhoneNumber, 11, '/n' ); //Similar to void. cin.getline or the getline member function. Here I am trying to get the compiler to input integers on the line and then remove the terminating characters

	cout<<"Phone Number before conversion: " << endl;
	cout << PhoneNumber << endl;

	for(int i = 0; i < 11; i++)
		{
		PhoneNumber[i] = LettertoNumber(PhoneNumber[i]);
		}

	cout<<"Phone Number after conversion: "<< endl;
	cout << PhoneNumber << endl;
	cout<<"****************************************" <<endl;
}
else if(input.compare("n"))
{
	cout<<"End of program"<<endl;
return 0;
}

int LettertoNumber(char letter)

	switch (letter)
		{
			case 'A':
			case 'B':
			case 'C':
			case 'a':
			case 'b':
			case 'c':
				return '2';
				break;
			case 'D':
			case 'E':
			case 'F':
			case 'd':
			case 'e':
			case 'f':
				return '3';
				break;
			case 'G':
			case 'H':
			case 'I':
			case 'g':
			case 'h':
			case 'i':
				return '4';
				break;
			case 'J':
			case 'K':
			case 'L':
			case 'j':
			case 'k':
			case 'l':
				return '5';
				break;
			case 'M':
			case 'N':
			case 'O':
			case 'm':
			case 'n':
			case 'o':
				return '6';
				break;
			case 'P':
			case 'Q':
			case 'R':
			case 'S':
			case 'p':
			case 'q':
			case 'r':
			case 's':
				return '7';
				break;
			case 'T':
			case 'U':
			case 'V':
			case 't':
			case 'u':
			case 'v':
				return '8';
				break;
			case 'W':
			case 'X':
			case 'Y':
			case 'Z':
			case 'w':
			case 'x':
			case 'y':
			case 'z':
				return '9';
				break;
			default:
				return letter; // in case it is not a letter or is already a number
				break;
		}

	}
}
Last edited on
Topic archived. No new replies allowed.