Help Using Switch to Switch a Letter to a Number in a Function

I'm new here and am just looking for some help. It would be greatly appreciated if someone could give me hint to help me with my project for simulating dialing a phone number. the part I need help on is the toDigit() function. In the toDigit() function I have to pass the variables by reference and if the its a letter that was inputted, lowercase has to be made to upper case and if the digit is valid return 0 or if the digit is invalid return -1. thanks for any help or hints!

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

//Function prototypes
int readDials(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8);
char toDigit(char &d1, char &d2, char &d3, char &d5, char &d6, char &d7, char &d8);
void acknowledgeCall(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8);

char d;
int returnValue = 0;
int main()
{
while (returnValue != -5)
{
char d1 = ' ', d2 = ' ', d3 = ' ', d4 = ' ', d5 = ' ', d6 = ' ', d7 = ' ', d8 = ' ';
readDials(d1, d2, d3, d4, d5, d6, d7, d8);

if (returnValue == -1)
{
cout << "ERROR - An invalid character was entered\n" << endl; continue;
}
else if (returnValue == -2)
{
cout << "ERROR - Phone number cannot begin with 0\n" << endl; continue;
}
else if (returnValue == -3)
{
cout << "ERROR - Phone number cannot begin with 555\n" << endl; continue;
}
else if (returnValue == -4)
{
cout << "ERROR - Hyphen is not in the correct position\n" << endl; continue;
}
else if (returnValue == -5)
{
returnValue = -5;
}
else
{
acknowledgeCall(d1, d2, d3, d4, d5, d6, d7, d8);
}
}
system("pause");
}

int readDials(char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8)
{
cout << "Enter a phone number(Q to quit): ";
cin >> d1;
if (d1 == 'Q' || d1 == 'q')
{
returnValue = -5;
return returnValue;
}
cin >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;

toDigit(d1, d2, d3, d5, d6, d7, d8);

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

return 0;
}

char toDigit(char &d1, char &d2, char &d3, char &d5, char &d6, char &d7, char &d8)
{
toupper(d);

switch (d)
{
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': returnValue = 0; break;
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;
default: returnValue = -1;
}
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 << "\n" << endl;
}


When I input letters as the number the end results show the same letters I entered. For example if I enter: abc-devg, it will say the number dialed is: abc-devg.
Last edited on
I have figured out the problem!
Topic archived. No new replies allowed.