Thread: C++ Phone Dialer Program

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    39

    C++ Phone Dialer Program

    I am having issues with my code giving me this error:

    1>LAB04.obj : error LNK2019: unresolved external symbol "void __cdecl AcknowledgeCall(char,char,char,char,char,char,char ,char)" (?AcknowledgeCall@@YAXDDDDDDDD@Z) referenced in function _main
    1>C:\Users\Zonen\documents\visual studio 2010\Projects\LAB04\Debug\LAB04.exe : fatal error LNK1120: 1 unresolved externals
    1>
    1>Build FAILED.


    any help and guidance would be really appreciated!

    this is my program:


    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    
    //Prototypes
    int ReadDials (char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8);
    int ToDigit (char &d);
    void AcknowledgeCall(char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8);
    char d = 0;
    
    using namespace std;
    
    
     int main()
     {
    	char d1, d2, d3, d4, d5, d6, d7, d8;
    	int ReturnValue = 0;
    
    	while (ReturnValue != -5)
    	{
    		ReturnValue = ReadDials(d1,d2,d3,d4,d5,d6,d7,d8);
    		switch(ReturnValue)
    		{
    		case -1: cout <<"ERROR- An invalid character was entered." << endl; break;
    		case -2: cout <<"ERROR- Phone number can't begin with 0." << endl; break;
    		case -3: cout <<"ERROR- Phone number can't begin with 555." << endl; break;
    		case -4: cout <<"ERROR- Hyphen is not in the correct posistion." << endl; break;
    		default: AcknowledgeCall(d1,d2,d3,d4,d5,d6,d7,d8);
    		}
    	}
    	return 0;
     } 
    
     int ReadDials (char & d1, char & d2, char & d3, char & d4, char & d5, char & d6, char & d7, char & d8)
    {
    	cout << "Enter a phone number: ";
    	cin >> d1;
    	if (d1 == 'Q' || d1 == 'q')
    		return -5;
    		cin >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;
    	int result = ToDigit(d);
    		ToDigit(d);
    	if (d == 0)
    		return -2;
    	if (d1 == 5 && d2 == 5 && d3 == 5)
    	return -3;
    	if (d4 != '-')
    	return -4;
    	if (result == -1)
    		return -1;
    	else 
    		return 0;
    
    }
    
    int ToDigit (char & d)
    	
    {
    	toupper(d);
    
    		switch(d)
    		{
    		case 'A': case 'B': case 'C':
    			d = '2'; return 0; break;			
    		case 'D': case 'E': case'F':
    			d = '3'; return 0; break;
    		case 'G': case 'H': case 'I':
    			d = '4'; return 0; break;
    		case 'J': case 'K': case 'L':
    			d = '5'; return 0; break;
    		case 'M': case 'N': case 'O':
    			d = '6'; return 0; break;
    		case 'P': case 'Q': case 'R': case 'S':
    			d = '7'; return 0; break;
    		case 'T': case 'U': case 'V':
    			d = '8'; return 0; break;
    		case 'W': case 'X': case 'Y': case 'Z':
    			d = '9'; return 0; break;
    		}
    	}
    
    
    		void AcknoweldgeCall(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;
    		}

  2. #2
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    Your function name is spelled wrong.
    Code:
    void AcknoweldgeCall(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;
    }
    Last edited by rmatze; 09-23-2011 at 02:19 PM.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    you have to be kidding me, after hours of looking that is what I missed!

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    now that is is up and running however it seems that my ToDigit() function is not properly converting the letters to numbers nor is my switch in the main() funtion passing out error codes. Any ideas?

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    ToDigit converts to '2', '3', etc. Those are ASCII characters, whose numeric values are 50, 51, etc in decimal. A char can contain numeric values like 2, 3, 4, so try:
    Code:
    case 'A': case 'B': case 'C':
        d = 2;  // notice no quotes ' '
        break;  // no need to return 0 here, do it at the end
    ...

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I would also suggest that you eliminate the global variable d, it is probably causing some of your problems.

    Jim

  7. #7
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    Quote Originally Posted by anduril462 View Post
    ToDigit converts to '2', '3', etc. Those are ASCII characters, whose numeric values are 50, 51, etc in decimal. A char can contain numeric values like 2, 3, 4, so try:
    Code:
    case 'A': case 'B': case 'C':
        d = 2;  // notice no quotes ' '
        break;  // no need to return 0 here, do it at the end
    ...
    ok I will try those ideas

  8. #8
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    Quote Originally Posted by jimblumberg View Post
    I would also suggest that you eliminate the global variable d, it is probably causing some of your problems.

    Jim
    when I get rid of that global variable the compiler tells me that int ToDigit(d); the d is undeclared.

  9. #9
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Well, of course. You still have to declare it, it just shouldn't be declared globally. Read this for details: Global Variables Are Bad.

    Move the declaration into main().

  10. #10
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    Quote Originally Posted by anduril462 View Post
    Well, of course. You still have to declare it, it just shouldn't be declared globally. Read this for details: Global Variables Are Bad.

    Move the declaration into main().
    thank you for the link, I made the adjustment

  11. #11
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    can anyone tell me what this means

    1>test.obj : error LNK2005: _main already defined in LAB04.obj
    1>C:\Users\Zonen\documents\visual studio 2010\Projects\LAB04\Debug\LAB04.exe : fatal error LNK1169: one or more multiply defined symbols found
    1>
    1>Build FAILED.

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It means you have two or more main functions defined in two or more source files.
    You cannot have more than one function with the same name.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    Zonen - I was looking at your code again, have you considered using a string for the phone number instead of chars?

  14. #14
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    Quote Originally Posted by rmatze View Post
    Zonen - I was looking at your code again, have you considered using a string for the phone number instead of chars?
    I have seen it done that way but for my class they want 8 individual variables

  15. #15
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    Ahh, I see. I was having a little fun today and I changed your code to use a string. That's why I asked. Did you get your code running?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Phone Conversion Program
    By jweidm02 in forum C++ Programming
    Replies: 10
    Last Post: 03-11-2010, 10:31 AM
  2. a phone book program
    By mackieinva in forum C Programming
    Replies: 2
    Last Post: 09-19-2007, 06:31 AM
  3. making a phone call in a program
    By jverkoey in forum C++ Programming
    Replies: 1
    Last Post: 03-18-2004, 05:09 PM
  4. phone directory program
    By cdummy in forum C Programming
    Replies: 1
    Last Post: 04-13-2002, 11:23 AM
  5. Dialer to connect my ISP through Modem
    By zahid in forum C++ Programming
    Replies: 0
    Last Post: 11-13-2001, 03:42 AM