Phone number formatter

Hello world=)
Im having problems with my C++ assignment, could anyone
help me please?
Im asked to write the following:
//***********************************************************
//This app formats 10 or 11 digit phone numbers as follows:
//12345678901 -> (234)-567-8901 for 11 digit phones, and
//1234567890 -> (123)-456-7890 for 10 digit phones.
//***********************************************************
#include <iostream> //as inp out
#include <string>
#include <iomanip>

using namespace std;

int main()
{
int phoneNumber;
int areaCode11, first3Numb11, reSt11;
int areaCode10, first3Numb10, reSt10;
int numbLength;
string LINE;
LINE = "****************************************";
cout << LINE << endl; // border
cout << "Welcome to the world's first Phone Number Formatter App !!! " << endl; // greetings
cout << LINE << endl; // border
cout << "_____________________________________________" << endl;
cout << endl;
cout << "Please enter a phone number that you want to format and press 'Enter':" << endl;
cout << "Note:Don't use spaces, dashes, or slashes." << endl;
cin >> phoneNumber; // phone typing

numbLength = phoneNumber.length(); // phone length

areaCode11 = phoneNumber.subtract(1,3); // area code of the 11 digit phone
first3Numb11 = phoneNumber.subtract(4,3); //first 3 digits of the 11 digit phone
reSt11 = phoneNumber.subtract(7,numbLength); //4 final digits of the 11 digit phone

areaCode10 = phoneNumber.subtract(0,3); // area code of the 10 digit phone
first3Numb10 = phoneNumber.subtract(3,3); // first 3 digits of the 10 digit phone
reSt10 = phoneNumber.subtract(6,numbLength); //4 final digits of the 10 digit phone

cout << endl; //space
cout << "The number you have entered is: " << phoneNumber << endl;
if (numbLength == 11) //condition
{
cout << "Your phone number contains 11 digits!"<< endl;
cout << "Here's your formated phone number: " << "(" << areaCode11 << ")" << "-" << first3Numb11 << "-" << reSt11 << endl;
}
else
{
cout << "Your phone number contains 10 digits!"<< endl;
cout << "Here's your formated phone number: " << "(" << areaCode10 << ")" << "-" << first3Numb10 << "-" << reSt10 << endl;
}
return 0;

}

i think it should work... but the only problem that Visual C++ underlines phoneNumber function in every function that uses it, says "expr. must have class type" but i declared it already...=( What does it want from me?(
Im first time here so sorry if i shouldnt be posting the whole code!
Last edited on
phoneNumber is an int. An int does not have class functions. It certainly does not have a function length, so this:
numbLength = phoneNumber.length();
will never work. The function you're trying to call does not exist.

Likewise for phoneNumber.subtract.
Uhmm..., so what i might use instead? its all based on the material from 3 first weeks...it cant be too advanced...
I would use a string.

Where did you get this "subtract" class function? No such class function exists for any class in the C++ definition. You can't just invent class function and hope they exist.
Topic archived. No new replies allowed.