error C2447: '{' : missing function header (old-style formal list?)

closed account (49ECpfjN)
I am having trouble with this C++ code. Can anybody help me?
#include <iostream>
#include <string>
#include <iomanip>
//prototypes
char toDigit(char&);
char readDial(char&,char&,char&,char&,char&,char&,char&,char&);
char acknowledgeCall(char d1,char d2,char d3,char d4,char d5,char d6,char d7,char d8);
char d1, d2, d3, d4, d5, d6, d7, d8;
using namespace std;

int main()
{
char readDial(char&,char&,char&,char&,char&,char&,char&,char&);
int returnValue = 0;
while (returnValue != -5)
{
switch(returnValue)
{
case -1: cout << "ERROR - An invalid character was entered" << endl; break;
case -2: cout << "ERROR - Phone number cannont begin with 0" << endl; break;
case -3: cout << "ERROR - Phone number cannont begin with 555" << endl; break;
case -4: cout << "ERROR - Hyphen is not in the correct position" << endl; break;
case -5: cout << "Good-bye" << endl; break;
default: acknowledgeCall(d1, d2, d3, d4, d5, d6, d7, d8);
}
}
return 0;
}
char toDigit(char&);
{
toupper(d);
switch(d)
{
case 'A': case 'B': case 'C':
d = '2'; break;
case 'D': case 'E': case 'F':
d = '3'; break;
case 'G': case 'H': case 'I':
d = '4'; break;
case 'J': case 'K': case 'L':
d = '5'; break;
case 'M': case 'N': case 'O':
d = '6'; break;
case 'P': case 'Q': case 'R': case 'S':
d = '7'; break;
case 'T': case 'U': case 'V':
d = '8'; break;
case 'W': case 'X': case 'Y': case 'Z':
d = '9'; break;
}
}
char readDial(char& d1, char& d2, char& d3, char& d4, char& d5, char& d6, char& d7, char& d8);
{
int retunValue;
cout << "Please enter a phone number or . to quit: " << endl;
cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;
if (d1 == '.')
{
return -5;
}
if (d1 == 0)
{
return - 2;
}

if (d1 == 5 && d2 == 5 && d3 == 5)
{
return -3;
}
if (d4 != '-')
{
return -4;
}
if (result == -1)
return -1;

if (ToDigit(d1,d2,d3,d5,d6,d7,d8) == -1)
return -1;

else
return 0;
phoneNumber = toDigit(char&);
}

char acknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8)
{
cout << "Phone number dialed: " << d1 << d2 << d3 << d4 << d5 << d6 << d7 << d8 << endl;
return 0;
}
It says error C2447: '{' : missing function header (old-style formal list?) on char toDigit (char &) and char readDial(char& d1, char& d2, char& d3, char& d4, char& d5, char& d6, char& d7, char& d8).
[code] "Please use code tags" [/code]
1
2
3
//in the definition of the functions
char toDigit(char&); //that semicolon should not be there
{
closed account (49ECpfjN)
I don't get "Please use code tags" . I am new to c++ so explain it please.
closed account (49ECpfjN)
I got rid of those semicolons but now I have more errors
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
 #include <iostream>
#include <string>
#include <iomanip>
//prototypes
char toDigit(char&);
char readDial(char&,char&,char&,char&,char&,char&,char&,char&);
char acknowledgeCall(char d1,char d2,char d3,char d4,char d5,char d6,char d7,char d8);
char d1, d2, d3, d4, d5, d6, d7, d8;
using namespace std;

int main()
{
char readDial(char&,char&,char&,char&,char&,char&,char&,char&);
int returnValue = 0;
while (returnValue != -5)
{
switch(returnValue)
{
case -1: cout << "ERROR - An invalid character was entered" << endl; break;
case -2: cout << "ERROR - Phone number cannont begin with 0" << endl; break;
case -3: cout << "ERROR - Phone number cannont begin with 555" << endl; break;
case -4: cout << "ERROR - Hyphen is not in the correct position" << endl; break;
case -5: cout << "Good-bye" << endl; break;
default: acknowledgeCall(d1, d2, d3, d4, d5, d6, d7, d8);
}
}
return 0;
}
char toDigit(char&)
{
toupper(d);
switch(d)
{
case 'A': case 'B': case 'C':
d = '2'; break;
case 'D': case 'E': case 'F':
d = '3'; break;
case 'G': case 'H': case 'I':
d = '4'; break;
case 'J': case 'K': case 'L':
d = '5'; break;
case 'M': case 'N': case 'O':
d = '6'; break;
case 'P': case 'Q': case 'R': case 'S':
d = '7'; break;
case 'T': case 'U': case 'V':
d = '8'; break;
case 'W': case 'X': case 'Y': case 'Z':
d = '9'; break;
}
}
char readDial(char& d1, char& d2, char& d3, char& d4, char& d5, char& d6, char& d7, char& d8)
{
int retunValue;
cout << "Please enter a phone number or . to quit: " << endl;
cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;
if (d1 == '.')
{
return -5;
}
if (d1 == 0)
{
return - 2;
}

if (d1 == 5 && d2 == 5 && d3 == 5)
{
return -3;
}
if (d4 != '-')
{
return -4;
}
if (result == -1)
return -1;

if (ToDigit(d1,d2,d3,d5,d6,d7,d8) == -1)
return -1;

else
return 0;
phoneNumber = toDigit(char&);
}

char acknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8)
{
cout << "Phone number dialed: " << d1 << d2 << d3 << d4 << d5 << d6 << d7 << d8 << endl;
return 0;
}

(31) : error C2065: 'd' : undeclared identifier
(32) : error C2065: 'd' : undeclared identifier
(32) : error C2050: switch expression not integral
(35) : error C2065: 'd' : undeclared identifier
(37) : error C2065: 'd' : undeclared identifier
(39) : error C2065: 'd' : undeclared identifier
(41) : error C2065: 'd' : undeclared identifier
(43) : error C2065: 'd' : undeclared identifier
(45) : error C2065: 'd' : undeclared identifier
(47) : error C2065: 'd' : undeclared identifier
(49) : error C2065: 'd' : undeclared identifier
(74) : error C2065: 'result' : undeclared identifier
(77) : error C3861: 'ToDigit': identifier not found
(82) : error C2065: 'phoneNumber' : undeclared identifier
(82) : error C2144: syntax error : 'char' should be preceded by ')'
(82) : error C2660: 'toDigit' : function does not take 0 arguments
(82) : error C2059: syntax error : ')'
Read your source code... those are mostly spelling errors you made.
closed account (49ECpfjN)
Modified the code, but guess what still some errors.
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
#include <iostream>
#include <string>
#include <iomanip>

//prototypes
char toDigit (char &);
char result;
char readDial(char& d1,char& d2,char& d3,char& d4,char& d5,char& d6,char& d7,char& d8);
char acknowledgeCall(char d1,char d2,char d3,char d4,char d5,char d6,char d7,char d8);
char d1, d2, d3, d4, d5, d6, d7, d8;
using namespace std;

int main()
{
	char readDial(char&,char&,char&,char&,char&,char&,char&,char&);
	int returnValue = 0;
	while (returnValue != -5)
	{
		switch(returnValue)
		{
		case -1: cout << "ERROR - An invalid character was entered" << endl; break;
		case -2: cout << "ERROR - Phone number cannont begin with 0" << endl; break;
		case -3: cout << "ERROR - Phone number cannont begin with 555" << endl; break;
		case -4: cout << "ERROR - Hyphen is not in the correct position" << endl; break;
		case -5: cout << "Good-bye" << endl; break;
		default: acknowledgeCall(d1, d2, d3, d4, d5, d6, d7, d8);
		}
	}
	return 0;
}
char toDigit(char&)
{ 
	switch(d1, d2, d3, d4, d5, d6, d7, d8)
	{
	case 'A': case 'B': case 'C':
		d1, d2, d3, d4, d5, d6, d7, d8 = '2'; break;
	case 'D': case 'E': case 'F':
		d1, d2, d3, d4, d5, d6, d7, d8 = '3'; break;
	case 'G': case 'H': case 'I':
		d1, d2, d3, d4, d5, d6, d7, d8 = '4'; break;
	case 'J': case 'K': case 'L':
		d1, d2, d3, d4, d5, d6, d7, d8 = '5'; break;
	case 'M': case 'N': case 'O':
		d1, d2, d3, d4, d5, d6, d7, d8 = '6'; break;
	case 'P': case 'Q': case 'R': case 'S':
		d1, d2, d3, d4, d5, d6, d7, d8 = '7'; break;
	case 'T': case 'U': case 'V':
		d1, d2, d3, d4, d5, d6, d7, d8 = '8'; break;
	case 'W': case 'X': case 'Y': case 'Z':
		d1, d2, d3, d4, d5, d6, d7, d8 = '9'; break;
	}
}
char readDial(char& d1, char& d2, char& d3, char& d4, char& d5, char& d6, char& d7, char& d8)
{	
	int retunValue;
	cout << "Please enter a phone number or . to quit: " << endl;
	cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;
	if (d1 == '.')
	{
		return -5;
	}
	if (d1 == 0)
	{
		return - 2;
	}

	if (d1 == 5 && d2 == 5 && d3 == 5)
	{
		return -3;
	}
	if (d4 != '-')
	{
		return -4;
	}
	if (result == -1)
	{
		return -1;
	}
	if (toDigit (char &)== -1)
	{
		return -1;
	}
	else
		return 0;
	d1,d2,d3,d5,d6,d7,d8 = toDigit(char &);
}

char acknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8)
{
	cout << "Phone number dialed: " << d1 << d2 << d3 << d4 << d5 << d6 << d7 << d8  << endl;
	return 0;
}

(85) : error C2144: syntax error : 'char' should be preceded by ')'
(85) : error C2660: 'toDigit' : function does not take 0 arguments
(85) : error C2059: syntax error : ')'
(86) : error C2143: syntax error : missing ';' before '{'
(89) : error C2181: illegal else without matching if
(91) : error C2144: syntax error : 'char' should be preceded by ')'
(91) : error C2660: 'toDigit' : function does not take 0 arguments
(91) : error C2059: syntax error : ')'
Last edited on
Topic archived. No new replies allowed.