I'm trying to code a C# homework assignment that takes a phone number in this format XXX-XXXX (8 digits that can be alphanumeric) and then "Define a method named ReadDials( ) that reads each digit/letter dialed into eight separate char variables (DO NOT USE ARRAYS). All digits are sent back through parameters by reference. "
There's a lot more to the assignment such as input validation, converting alpha-numeric data to individual numeric characters, testing for phone number validity,
I think I'm already in the weeds a bit since the pseudocode supplied has the loop and validation in the ReadDials method. The pseudocode requirements follow as well.
// Pseudocode
Using the pseudocode below, write the code that will meet the requirements:
Main Method
Declare the char variables for the 8 digits of the phone number
While true
Call the ReadDials( ) method 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 Acknowledge Call function
End-While
ReadDials( ) method
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 ( ) method
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 ( ) method
Display the Phone Number.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lab4_2
{
class Program
{
// ReadDials method initial code
static char ReadDials(string PhoneNo, int myCounter)
{
char holder; // variable to store individual character from string
holder = (char)PhoneNo[myCounter]; // parse value in counter position
return holder; return single value to Main ()
}
static void Main(string[] args)
{
char digit1, // Declare 8 variables for individual characters
digit2,
digit3,
digit4,
digit5,
digit6,
digit7,
digit8;
string phoneNo;
// Get console input
Console.WriteLine("Enter a phone number (Q to quit)");
phoneNo = Console.ReadLine();
int myCounter = 1;
do
{
digit1 = ReadDials(phoneNo, myCounter);
myCounter++;
}
while (myCounter < 8);
Obviously, the do loop in the main won't work, because I can't think of a way to loop the call to ReadDials() without using an array. I'm not looking for anyone to code for me. I really want to learn C#. I'm just looking for help or ideas on how to fulfill the project requirements... logic help, if you will.
I suppose that the first step would be change the Main() to a While loop to satisfy the pseudocode requirements, though I can't envision the logic involved. Anyone want to give me a hand with general program structure. Specific coding not necessary. I just need logic help / structure help... or a nudge in the right direction...
Any help is appreciated.
Jim