Void Functions

hey guys...

I am doing an assignment for my c++ class and I am running into trouble with a Void Function. The teacher says this:

"Set up this as a void function and pass letter by value to the function. The purpose of the function is to display the ICAO alphabetic character that corresponds to letter. No value is returned."

I am getting this when I try to compile:

1>------ Build started: Project: ch7ex1, Configuration: Debug Win32 ------
1> ch7ex1.cpp
1>ch7ex1.obj : error LNK2019: unresolved external symbol "void __cdecl displayChar(char)" (?displayChar@@YAXD@Z) referenced in function _main
1>c:\users\sean\documents\visual studio 2010\Projects\ch7ex1\Debug\ch7ex1.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Here is my code I have so far (won't compile):

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
//Input String, output series of strings
//This program allows the user to input a word and it will ouput a series of ICAO words
//using the corresponding International Civil Aviation Organization alphabet words
// Example : hello = Hotel Echo Lime Lima Oscar

#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;

//Function prototype
void displayChar(char);

int main()
{
	string instring, sub;
	char letter;
	int len, ipos;

	instring = (" cin >>instring; ");
	cout << "The phonetic version for" << instring <<  " is: ";
	len = instring.length() ;

	ipos = 0;
	while (ipos <= len-1)
{
	sub = instring.substr(ipos, 1);
	letter = sub[0];
	if (isalpha(letter) == 0)
		cout << "Will skip character " << letter <<  endl;
	else
	displayChar(letter) ;
	ipos = ipos + 1;
}

	 switch (letter)
{
    case 'A': case 'a': cout << "Alpha";                              
		break;
	case 'B': case 'b': cout << "Bravo";
		break;
	case 'C': case 'c': cout << "Charlie";
		break;
	case 'D': case 'd': cout << "Delta";
		break;
	case 'E': case 'e': cout << "Echo";
		break;
	case 'F': case 'f': cout << "Foxtrot";
		break;
	case 'G': case 'g': cout << "Golf";
		break;
	case 'H': case 'h': cout << "Hotel";
		break;
	case 'I': case 'i': cout << "India"; 
		break;
	case 'J': case 'j': cout << "Juliet";
		break;
	case 'K': case 'k': cout << "Kilo";
		break;
	case 'L': case 'l': cout << "Lima";
		break;
	case 'M': case 'm': cout << "Mike";
		break;
	case 'N': case 'n': cout << "November";
		break;
	case 'O': case 'o': cout << "Oscar";
		break;
	case 'P': case 'p': cout << "Papa";
		break;
	case 'Q': case 'q': cout << "Quebec";
		break;
	case 'R': case 'r': cout << "Romeo";
		break;
	case 'S': case 's': cout << "Sierra";
		break;
	case 'T': case 't': cout << "Tango";
		break;
	case 'U': case 'u': cout << "Uniform";
		break;
	case 'V': case 'v': cout << "Victor";
		break;
	case 'W': case 'w': cout << "Whiskey";
		break;
	case 'X': case 'x': cout << "X-Ray";
		break;
	case 'Y': case 'y': cout << "Yankee";
		break;
	case 'Z': case 'z': cout << "Zulu";
		break;
	default : cout << "You entered an invalid letter";
}

	//Hit any key to close 
	system("Pause");
	return 0;
}



any help would be very appreciated! Thanks!
you don't seem to define void displayChar(char) anywhere.

And what's going on on line 21?
Last edited on
Oops... I think line 21 should be: cin >> instring

The defining it part is what I am stuck on. We have not covered functions yet...
A function is just like in main(); you can make it do anything you want.

You can put the entire switch in there, and pass the character over to it, then it uses the passed variable to decide which cout statement to use.

By the way, you misspelled "Alfa"
There's another oops!!! Thanks for pointing that out ciphermagi!

Am I not defining it on line 13?

Can you give me a coding example without giving too much away? I'm trying to learn here and not just cut and paste solutions to my problems into my code.

Thanks!

Line 13 is simply the prototype. Take a look at this code and see what you're missing :P A tip for you would be to indent your braces - it will help you see the problem easier (;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

//myFavoriteNumber prototype
void myFavoriteNumber(int);

int main()
{
cout << "What's your favorite number? ";
int fave;
cin >> fave;
myFavoriteNumber(fave);

return 0;
}


//start of myFavoriteNumber function
void myFavoriteNumber(int f)
{
cout << " I heard your favorite number was..." << f << " ! That's mine too!";
}


Last edited on
You just need to "relocate" your switch statement into the displayChar function, following georgewashere's example.
I am having the same problem with this and maybe I am having a brain fart or just brain fried but still not getting this.
Topic archived. No new replies allowed.