Thread: C++ Phone Dialer Program

  1. #16
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    no I am having trouble understanding what eylsia meant by having the main function defined in two or more sources.

  2. #17
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    actually I figured it out, I created a second file to test and had to remove it, now I can compile but for some reason it doesn't seem to be properly reading the numbers and relaying to my switch with the errors.

  3. #18
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    when I enter the number 555 it is supposed to give back an error from the main function switch that says you can't have a number that starts with 555 but instead all it does is sit there blinking and now responding. Not sure what in my code is wrong because in theory I thought everything looked good. not to mention if I type in a 8 character value like 565-2311 it says hyphen is in wrong position which is from my error switch and that isnt true. I don't know what I did wrong here.
    Last edited by zonen; 09-23-2011 at 06:10 PM.

  4. #19
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    matze when you made the changes you were talking about did it actually compile and do what it is supposed to do? Mine never actually properly read the numbers and through out errors like I needed it too. I am still stuck on what I messed up that it isnt doing right.

  5. #20
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Thanks for all the updates however it really isn't necessary, you could have just edited your last post instead of bumping your own thread. You need to post your updated code.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  6. #21
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    here is my updated code with issues still:


    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <cctype>
    
    //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);
    
    
    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)
    {
    	char d = 0;
    	cout << "Enter a phone number or Q to quit: ";
    	cin >> d1;
    	if (d1 == 'Q' || d1 == 'q')
    		return -5;
    		cin >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;
    	int result = ToDigit(d);
    		if (d1 == 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; 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;
    		}
    		return 0;
    	}
    
    
    		void 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;
    		}

  7. #22
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    You only call your Todigit function once, and that is with a d you declared in the calling function. No where in your code are you actually converting anything from your input. What exactly do the requirements say?
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  8. #23
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    I am supposed to be able to enter any form of a phone number for example 459-5647 should return that exactly, however if I ahve a 555-4513 it should bring back an error stating that you cant have a number with 555 as well as if you start with a 0 then there should be an error. You also need to be able to type letters so
    abc-defg should come out as 222-3334 when ToDigit converts it.

  9. #24
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Ok, well you aren't really doing any of that. Can you use a char array? Do you know of the ctype library and the functions isdigit and isalpha? Those would be great starting points.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  10. #25
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    I know that isalpha is supposed to check for the case I believe

  11. #26
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    I dont think I can use arrays yet though.

  12. #27
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    I think I finally understand why your saying that my program isnt doing what it should be doing. How about if I do my ReadDials function like this:
    Code:
    int ReadDial (char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8)
    {
        int returnValue = 0;
        cout << "Enter a phone number (Q to quit): ";
        cin >> d1; 
        if(d1 == 'Q' || d1 == 'q') return -5; 
        cin >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;  
        returnValue = Todigit(d1);
        if (returnValue == -1)
            return returnValue;
        returnValue = Todigit(d2);
        if (returnValue == -1)
            return returnValue;
        returnValue = Todigit(d3);
        if (returnValue == -1)
            return returnValue;
        if (d4 != '-')
            return -4;
        returnValue = Todigit(d5);
        if (returnValue == -1)
            return returnValue;
        returnValue = Todigit(d6);
        if (returnValue == -1)
            return returnValue;
        returnValue = Todigit(d7);
        if (returnValue == -1)
            return returnValue;
        returnValue = Todigit(d8);
        if (returnValue == -1)
            return returnValue;
        if (d1 == '0')
            return -2;
        if (d1 == '5' && d2 == '5' && d3 == '5')
            return -3;
        return 0;
     
    }

  13. #28
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Are you sure? This seems like an array problem to me. Did you cover them in class yet? Does the hw assignment say a "grouping" of chars or any derivation. This assigment basically flows:
    1. Get input from user in format xxx-xxxx
    2. iterate through input:
    3. if first num is 0 then error else if alpha convert to number and store
    4. continue iteration if - located any position besides 4, error. Else if alpha convert number and store
    5. if first 3 numbers are 5 then error
    6. output converted number.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  14. #29
    Registered User
    Join Date
    Sep 2011
    Posts
    39
    ya I just looked, says no arrays, but does that code above look right?

  15. #30
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by zonen View Post
    ya I just looked, says no arrays, but does that code above look right?
    Does it run and work? I am afraid your code is a bit all over the place. I think you are writing over your return value and your main error logic looks hazy. Follow the steps I posted only do them for each char instead of the iterating.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

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