Returns not working - Telephone Assignment

Mar 27, 2017 at 12:51am
Having problems here. I've been trying to work this out on my own for the last several days but it' just not working.
I need this code to check my if statements and return either -5, -4, -3, -2, -1, or continue the rest of the functions.
The ToDigit functions and the AcknowledgeCall Functions do what their supposed to and the ReadDials asks the questions and takes in the numbers:
However it Does not error out per the if statements - it just keeps going.

What am I not seeing or understanding?
Your help is appreciated.


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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <iostream>
#include <ostream>
#include <iomanip>
using namespace std;

//Function Declaration
int ReadDials(char &n1, char &n2, char &n3, char &n4, char &n5, char &n6, char &n7, char &n8);
int ToDigit(char &digit);
void AcknowledgeCall(char n1, char n2, char n3, char n4, char n5, char n6, char n7, char n8);

int main()
{
	char n1, n2, n3, n4, n5, n6, n7, n8;
	n1 = ' ';
	n2 = ' ';
	n3 = ' ';
	n4 = ' ';
	n5 = ' ';
	n6 = ' ';
	n7 = ' ';
	n8 = ' ';

	int ErrorResult = 0;
		
	do
	{	
		ReadDials(n1, n2, n3, n4, n5, n6, n7, n8);
		/*	if (ErrorResult == -2)
			{
				cout << "ERROR - Phone number cannont begin with 0; Please Try Again." << endl;
				cout << "Enter a 8 digit telephone number: ";
				cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
			}
			if (ErrorResult == -3)
			{
				cout << "ERROR - Phone number cannont begin with 555; Please Try Again." << endl;
				cout << "Enter a 8 digit telephone number: ";
				cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
			}
	
		if (ErrorResult == -4)
			{
				cout << "ERROR - Hyphen is not in the correct position; Please Try Again." << endl;
				cout << "Enter a 8 digit telephone number: ";
				cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
			}*/
	AcknowledgeCall(n1, n2, n3, n4, n5, n6, n7, n8);
		
	} while (ErrorResult!=-5); 
	

}

//Function Definitions
int ReadDials(char &n1, char &n2, char &n3, char &n4, char &n5, char &n6, char &n7, char &n8)
{
	do
	{
	cout << "Enter a 8 digit telephone number: ";
	cin >> n1 >> n2;

	} while ((n1 != 'q') || (n1 != 'Q'));

	cin >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
	cout << endl;

	
	if (n1 == 5 && n2 == 5 && n3 == 5)
	{
		cout << "ERROR - Phone number cannont begin with 555; Please Try Again." << endl;
		cout << "Enter a 8 digit telephone number: ";
		return -2;
		cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
	}
	if (n1 == 0)
	{
		cout << "ERROR - Phone number cannont begin with 0; Please Try Again." << endl;
		cout << "Enter a 8 digit telephone number: ";
		return -3;
		cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
	}
	if (n1 == '-' || n2 == '-' || n3 == '-' || n5 == '-' || n6 == '-' || n7 == '-' || n8 == '-')
	{
		cout << "ERROR - Hyphen is not in the correct position; Please Try Again." << endl;
		cout << "Enter a 8 digit telephone number: ";
		return -4;
		cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
	}
	
	ToDigit(n1);
	ToDigit(n2);
	ToDigit(n3);
	ToDigit(n4);
	ToDigit(n5);
	ToDigit(n6);
	ToDigit(n7);

}

int ToDigit(char &digit)
{
char result;
result = ' ';
digit = toupper(digit);

switch (digit)
{
case 'A':
case 'B':
case 'C':
case '2':
result = '2';
break;
case 'D':
case 'E':
case 'F':
case '3':
result = '3';
break;
case 'G':
case 'H':
case 'I':
case '4':
result = '4';
break;
case 'J':
case 'K':
case 'L':
case '5':
result = '5';
break;
case 'M':
case 'N':
case 'O':
case '6':
result = '6';
break;	
case 'P':
case 'Q':
case 'R':
case 'S':
case '7':
result = '7';
break;
case 'T':
case 'U':
case 'V':
case '8':
result = '8';
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
case '9':
result = '9';
break;
case '0':
	result = '0';
case '1':
	result = '1';
case '-':
	result = '-';

break;
default:
result=-1;
}
digit = result;

return result;

}
void AcknowledgeCall(char n1, char n2, char n3, char n4, char n5, char n6, char n7, char n8)
{
	cout << "Phone Number is: " << n1 << n2 << n3 << n4 << n5 << n6 << n7 << n8 << endl;

}
Mar 27, 2017 at 1:39am
Alright - I can get the if statements to check but I don't know how to incorporate the returns to be -5, and quit
-4 and cout error
-3 and cout corresponding error
-2 and cout corresponding error
-1 and cout corresponding error
New Question - I need to do an if statement (I think that's the method), that errors out to a -1 if there is a non letter or number entered (invalid entry)
Thanks again!
For anyone interested here is my updated code:
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <iostream>
#include <ostream>
#include <iomanip>
using namespace std;

//Function Declaration
int ReadDials(char &n1, char &n2, char &n3, char &n4, char &n5, char &n6, char &n7, char &n8);
int ToDigit(char &digit);
void AcknowledgeCall(char n1, char n2, char n3, char n4, char n5, char n6, char n7, char n8);

int main()
{
	char n1, n2, n3, n4, n5, n6, n7, n8;
	n1 = ' ';
	n2 = ' ';
	n3 = ' ';
	n4 = ' ';
	n5 = ' ';
	n6 = ' ';
	n7 = ' ';
	n8 = ' ';

	int ErrorResult = 0;
		
	do
	{	
		ReadDials(n1, n2, n3, n4, n5, n6, n7, n8);
		/*	if (ErrorResult == -2)
			{
				cout << "ERROR - Phone number cannont begin with 0; Please Try Again." << endl;
				cout << "Enter a 8 digit telephone number: ";
				cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
			}
			if (ErrorResult == -3)
			{
				cout << "ERROR - Phone number cannont begin with 555; Please Try Again." << endl;
				cout << "Enter a 8 digit telephone number: ";
				cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
			}
	
		if (ErrorResult == -4)
			{
				cout << "ERROR - Hyphen is not in the correct position; Please Try Again." << endl;
				cout << "Enter a 8 digit telephone number: ";
				cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
			}*/
	AcknowledgeCall(n1, n2, n3, n4, n5, n6, n7, n8);
		
	} while (ErrorResult!=-5); 
	

	system("pause");

}

//Function Definitions
int ReadDials(char &n1, char &n2, char &n3, char &n4, char &n5, char &n6, char &n7, char &n8)
{
	cout << "Enter a 8 digit telephone number: ";
	cin >> n1;
	if ((n1 == 'q') || (n1 == 'Q'))
	{
		return -5;
	}

	cin >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
	cout << endl;

	
	if ((n1 == '5') && (n2 == '5') && (n3 == '5'))
	{
		cout << "ERROR - Phone number cannont begin with 555; Please Try Again." << endl;
		return -2;
		cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
	}
	if (n1 == '0')
	{
		cout << "ERROR - Phone number cannont begin with 0; Please Try Again." << endl;
		return -3;
		cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
	}
	if ((n1 == '-') || (n2 == '-') || (n3 == '-') || (n5 == '-') || (n6 == '-') || (n7 == '-') || (n8 == '-'))
	{
		cout << "ERROR - Hyphen is not in the correct position; Please Try Again." << endl;
		return -4;
		cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6 >> n7 >> n8;
	}
	
	ToDigit(n1);
	ToDigit(n2);
	ToDigit(n3);
	ToDigit(n4);
	ToDigit(n5);
	ToDigit(n6);
	ToDigit(n7);
	ToDigit(n8);

}

int ToDigit(char &digit)
{
char result;
result = ' ';
digit = toupper(digit);

switch (digit)
{
case 'A':
case 'B':
case 'C':
case '2':
result = '2';
break;
case 'D':
case 'E':
case 'F':
case '3':
result = '3';
break;
case 'G':
case 'H':
case 'I':
case '4':
result = '4';
break;
case 'J':
case 'K':
case 'L':
case '5':
result = '5';
break;
case 'M':
case 'N':
case 'O':
case '6':
result = '6';
break;	
case 'P':
case 'Q':
case 'R':
case 'S':
case '7':
result = '7';
break;
case 'T':
case 'U':
case 'V':
case '8':
result = '8';
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
case '9':
result = '9';
break;
case '0':
	result = '0';
	break;
case '1':
	result = '1';
	break;
case '-':
	result = '-';
break;
default:
result=-1;
}
digit = result;

return result;

}
void AcknowledgeCall(char n1, char n2, char n3, char n4, char n5, char n6, char n7, char n8)
{
	cout << "Phone Number is: " << n1 << n2 << n3 << n4 << n5 << n6 << n7 << n8 << endl;

}

Topic archived. No new replies allowed.