I am trying to work on this program for class and have been stuck for weeks. This is what I am supposed to be doing
Step 2: Processing Logic
Using the pseudo code below, write the code that will meet the requirements:
Main Function
Declare the char variables for the 8 digits of the phone number
while true
Call the ReadDials function passing the 8 digits
by reference. ReadDials returns an error code by
value.
If the return value is -5, exit the do while loop
If the error code is -1, display the
error message "ERROR - An invalid character was entered".
If the error code is -2, display the
error message "ERROR - Phone number cannot begin with 0".
If the error code is -3, display the
error message "ERROR - Phone number cannot begin with 555".
If the error code is -4, display the
error message "ERROR - Hyphen is not in the correct position".
Otherwise, call the AcknowledgeCall function
End-While
ReadDials function
Input the first digit
If a Q was entered, return -5.
Input the rest of the phone number
Call the ToDigit function for each of the 7 digits
not for digit 4
If ToDigit returns -1, return -1
If digit 4 is not a hyphen, return -4.
If digit 1 is 0, return -2.
If digits 1 - 3 are 5, return -3
Otherwise, return 0
ToDigit function
Convert the digit to upper case
Use a switch statement to determine if the digit is valid
and convert the letters to digits
If the digit is invalid, return -1.
If the digit is valid, return 0.
AcknowledgeCall function
Display the Phone Number.
Step 3: Create a new project
Create a new project and name it LAB4.
Write your code using the Processing Logic in Step 2 (above). Make sure you save your program.
Step 4: Compile and Execute
a) Compile your program. Eliminate all syntax errors.
b) Build your program and verify the results of the program. Make corrections to the program logic if necessary until the results of the program execution are what you expect.
THIS WHAT I HAVE
#include <iostream>
using namespace std;
int readDials(int, int , int , int , int , int , int , int);
int toDigit (int,int,int,int,int,int,int,int);
int acknowledgeCall (int, int,int,int,int,int,int,int);
int main()
{
int result = 0;
int returnValue = 0;
while (returnValue != -6)
{
returnValue = result;
switch (returnValue)
{
case -1: cout << "ERROR - An invalid character was entered" << endl; break;
case -2: cout << "ERROR - Phone number cannot begin with 0" << endl; break;
case -3: cout << "ERROR - Phone number cannot begin with 555" << endl; break;
case -4: cout << "ERROR - Hyphen is not in the correct position" << endl; break;
case -5: cout << "Good bye!!!" << endl; break;
}
}
return 0;
}
int readDials(int num1&, int num2&, int num3&, int num4&, int num5&, int num6&, int num7&, int num8&)
{
int num1,num2,num3,num4,num5,num6,num7,num8;
cout << "Please enter the first digit or q to exit." << endl;
cin >> num1;
if (num1 == 'Q' || num1 == 'q')
return -5;
cout << "please continue with the remainder of the phone number." << endl;
cin >> num2 >> num3 >> num4 >> num 5 >> num6 >> num7 >> num8;
int result = toDigit(num1, num2, num3, num4, num5, num6, num7, num8);
{
if (result == -1)
return -1;
if resuelt == -2)
return -2;
if (result == -3)
return -3;
if result == -4)
return -4;
else if (result != -1 || result != -2 || result != -3 || result != -4)
return 0;
}
return result;
}
int toDigit (int num1&, int num2&, int num3&, int num4&, int num5&, int num6&, int num7&, int num8&)
{
if (num1 == 5 && num2 == 5 && num3 == 5)
return -3;
if (num1 == 0)
return -2;
if (num4 !='-')
return -4;
switch (num1, num2, num3, num5, num6, num7, num8)
{
case 'a':
cout << "2";
break;
case 'A':
cout << "2";
break;
case 'b':
cout << "2";
break;
case 'B':
cout << "2";
break;
case 'c':
cout << "2";
break;
case 'C':
cout << "2";
break;
case 'd':
cout << "3";
break;
case 'D':
cout << "3";
break;
case 'f':
cout << "3";
break;
case 'F':
cout << "3";
break;
case 'g':
cout << "4";
break;
case 'G':
cout << "4";
break;
case 'h':
cout << "4";
break;
case 'H':
cout << "2";
break;
case 'i':
cout << "4";
break;
case 'I':
cout << "4";
break;
case 'j':
cout << "5";
break;
case 'J':
cout << "5";
break;
case 'k':
cout << "5";
break;
case 'K':
cout << "5";
break;
case 'l':
cout << "5";
break;
case 'L':
cout << "5";
break;
case 'M':
cout << "6";
break;
case 'm':
cout << "6";
break;
case 'o':
cout << "6";
break;
case 'O':
cout << "6";
break;
case 'p':
cout << "7";
break;
case 'P':
cout << "7";
break;
case 'q':
cout << "7";
break;
case 'Q':
cout << "7";
break;
case 'r':
cout << "7";
break;
case 'R':
cout << "7";
break;
case 's':
cout << "7";
break;
case 'S':
cout << "7";
break;
case 't':
cout << "8";
break;
case 'T':
cout << "8";
break;
case 'u':
cout << "8";
break;
case 'U':
cout << "8";
break;
case 'v':
cout << "8";
break;
case 'w':
cout << "9";
break;
case 'W':
cout << "9";
break;
case 'x':
cout << "9";
break;
case 'X':
cout << "9";
break;
case 'y':
cout << "9";
break;
case 'Y':
cout << "9";
break;
case 'z':
cout << "9";
break;
case 'Z':
cout << "9";
break;
return 0;
}
}
void acknowledgeCall (int num1, int num2, int num3, int num4, int num5, int num6, int num7, int num8)
{
cout << "the number is" << num1 << num2 << num3 << num4 << num5 << num6 << num7 << num8;
return 0;
}
Your switch statement within your toDigit() function is incorrect: You can only switch on one value. You will have to call toDigit() for each number entered.
Thanks, I will call it for each number and to hasula I was thanks for telling me how to input the code, I have been trying to figure that out for a while.