如果输入 Q 或 q,需要程序关闭。
但目前它并没有关闭并显示电话号码并关闭。
如果你能帮助我,请发帖谢谢!
到目前为止,我目前拥有此代码并且它可以工作,但是当返回 -5 时,我不会停止 while 循环。
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int readDial ( char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8);
char toDigit (char &d);
void acknowledgeCall (char d1, char d2, char d3, char d4, char d5, char d6, char d7, char d8);
int main ()
{
char d1, d2, d3, d4 , d5, d6, d7, d8;
int returnV = false;
while (returnV != -5)
{
returnV = readDial (d1,d2,d3,d4,d5,d6,d7,d8);
switch (returnV)
{
case -1: cout << "Error - An invalid Character was entered.\n";
case -2: cout << "Error - Phone Number cannot begin with 0.\n";
case -3: cout << "Error - Phone Number cannot begin with 555.\n";
case -4: cout << "Error - Hyphen is not in the correct spot.\n";
default: acknowledgeCall (d1, d2, d3,d4, d5,d6,d7,d8);
}
}
system("pause");
return 0;
}
int readDial ( char &d1, char &d2, char &d3, char &d4, char &d5, char &d6, char &d7, char &d8)
{
int returnV;
cout << " Enter The Phone Number (Q to Quit): ";
cin >> d1;
if( d1 == 'Q' || d1 == 'q')
return -5;
cin >> d2 >> d3 >> d4 >> d5 >> d6 >> d7 >> d8;
returnV = toDigit(d1);
if (returnV == -1)
return returnV;
returnV = toDigit(d2);
if (returnV == -1)
return returnV;
returnV = toDigit(d3);
if(d4 != '-')
return -4;
returnV = toDigit(d5);
if (returnV == -1)
return returnV;
returnV = toDigit(d6);
if (returnV == -1)
return returnV;
returnV = toDigit(d7);
if (returnV == -1)
return returnV;
returnV = toDigit(d8);
if (returnV == -1)
return returnV;
if (d1 == '0')
return -2;
if (d1 == '5' && d2 == '5' && d3 == '5')
return -3;
return 0;
}
char toDigit (char &d)
{
d = toupper (d);
switch (d)
{
case '0': case '1' : case '2' : case '3': case '4' : case '5' : case '6' : case '7' : case '8' : case '9':
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: return -1;
}
}
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\n ";
}