Look over my program? What did I do wrong?

// preprocessor directives
#include <iostream>
#include <string> // string class library
#include <iomanip> // setw(), fixed, showpoint, setprecision, left, right
using namespace std;


/* Function: main() *************************************************
*
* application entry point
* TODO: code main() according to pseodocode in directions handout
*/

// STUDENT CODE BEGINS

int main()
{
string enterPhoneNumber();
int isValid(string PhoneNumber);
string formatNumber(string PhoneNumber);
void displayResults(int status, string PhoneNumber);
void printHeading();

// #3: declare utility functions (like print headings function)
printHeading();

//#4: declare local variables
string PhoneNumber;
int length;
int status;
string NewPhoneNumber;
string choice;

//used for input, processing, output
//#5: declare program loop exit variable
//main() must have a program loop

printHeading();

do
{

PhoneNumber = enterPhoneNumber();
status = isValid(PhoneNumber);
PhoneNumber = formatNumber(PhoneNumber);
void displayResults(int status, string PhoneNumber);

cout << "More phone numbers? (y/n): ";
cin >> choice;

cout << endl << "..................." << endl;

} while (choice == "y" || choice == "Y");

cout << "End of program." << endl;

cin.ignore();
cin.get();
return 0;


// STUDENT CODE ENDS



//-------------------------------------------------------------------
// General Functions
//-------------------------------------------------------------------

//
// input functions
//

/* Function: enterPhoneNumber() ************************************
* parameters: none
* return: phoneNumber : string
*
* Comments
* -prompt & get a telephone number
*
* TODO: code the enterPhoneNumber() function below this comment
*/

// STUDENT CODE BEGINS

//phoneNumber = enterPhoneNumber();

//status =isValid(phoneNumber);

//if (status = 0)
//{
//formattedPhoneNumber = formatNumber(phoneNumber);

//if (status = 0)
//{
//else------string enterPhoneNumber;


string PhoneNumber;

{
// declare local identifier
string PhoneNumber;

// assign a value to identifier
cout << "Enter Phone Number: ";
cin >> PhoneNumber;

// return value
return PhoneNumber;
}


// STUDENT CODE ENDS


//
// processing functions
//


/* Function: isValid() *******************************************
* parameters: phoneNumber : string
* return: status: int
* return a status of 0 if all is OK
* return a status of 1 if length is not 8 or 11
* return a status of 2 if first character not a 1
* return a status of 3 if number is not all digits 0-9
*
* TODO: code the isValid() function below this comment
*/

// STUDENT CODE BEGINS

// isValid() function
// NOTE about the integer value to be returned
// * return a status of 0 if all is OK
// * return a status of 1 if length is not 8 or 11
// * return a status of 2 if first character not a 1
// * return a status of 3 if number is not all digits 0-9

int isValid(string PhoneNumber)

{

int status;



if (PhoneNumber.length() != 8 && PhoneNumber.length() != 11)
status = 1;



else if (PhoneNumber.at(0) != '1')

status = 2;


else if (PhoneNumber.find_first_not_of("023456789", 0))

status = 3;

else // phone number is valid

status = 0;

return status;
}


// STUDENT CODE ENDS



/* Function: formatNumber() *****************************************
* parameters: phoneNumber : string (unformatted phone number)
* return: phoneNumber: string
* return an 8 digit phone number formatted like: 1-555-6789
* return an 11 digit phone number formatted like: 1-(234)-555-6789
*
* TODO: code the formatNumber() function below this comment
*/

// STUDENT CODE BEGINS
string formatNumber(string PhoneNumber)

{
int length;
string formatNumber;
string NewPhoneNumber;

if (PhoneNumber.length() == 8)
{
NewPhoneNumber.insert(1, "-");
NewPhoneNumber.insert(5, "-");
}
else if (PhoneNumber.length() == 11)
{
NewPhoneNumber.insert(5, "-(");
NewPhoneNumber.insert(6, ")-");
NewPhoneNumber.insert(11, "-");
}
return ;


}


// STUDENT CODE ENDS



//
// output functions
//

/* Function: displayResults() ***************************************
* parameters: status : int (values 0-3)
* formattedNumber : string
* return: none: void
*
* TODO: code the displayResults() function below this comment
*/

// STUDENT CODE BEGINS

void displayResults(int status, string NewPhoneNumber);

{
if (status == 0);
{

cout << "Formatted number is: " << PhoneNumber;

}


else if (status > 0);
{


cout << "Invalid phone number: " << PhoneNumber;

cout << "Your call cannot be completed because: ";

}

else if (status == 1);
{

cout << "A phone number must have 8 or 11 characters.";
cout << "Invalid phone number: " << PhoneNumber;

}

else if (status == 2);
{

cout << "A phone number must begin with a 1.";
cout << "Invalid phone number: " << PhoneNumber;

}


else if (status == 3);
{

cout << "A phone number must contains only digits 0-9.";
cout << "Invalid phone number: " << PhoneNumber;

}

else
{

cout << "Please try again.";

}
}



// STUDENT CODE ENDS


//-------------------------------------------------------------------
// Utility Functions
//-------------------------------------------------------------------


/* Function: printHeading() **************************************
* return: void
*
* TODO: replace "<your name here>" with your name like
* "Joe Blough" <- remove < and > also!
*/
void printHeading();
{
/* declarations *************************************************/
// if any

/* statements ***************************************************/


// print program and programmer information
cout << endl;

cout << "Project/program name: U05_Telephone" << endl;
cout << "by" << endl;
cout << "<your name here>" << endl;

cout << endl;

// program title
cout << "Telephone Number Verification Program";
cout << endl << endl;

// program introduction and directions
cout << "\nWelcome to the Telephone Number Verification program. ";
cout << "\nWhen prompted, please enter either an 8 digit telephone number ";
cout << "\nor an 11 digit telephone number. Valid telephone numbers ";
cout << "\nwill always begin with 1, always have 8 digits or 11 digits, and ";
cout << "\ncontain only the digits 0-9." ;

cout << endl << endl;

return;
}
What did you do wrong?
First of all you didn't use the source code format button (<>)
Second, you gave us heaps of code without telling us what errors you're getting or what the program even does.....


Also the people on this forum are not here to do your homework....
Last edited on
Topic archived. No new replies allowed.