Need help adding a dash/hyphen in this code

I need to add a dash (-) in the phone numbers in the code. I also need to detect and display a message saying the number has double digits in the 7 digit number:
Here is what the output should look like:
The phone number is: 
(800)867-5309
Printing phone number stats!
 Country code:  43
 Area code:     800
 Phone number:  8675309
 Type:          H
 Year:          1981

The phone number is: 
(415)867-5555
Printing phone number stats!
 Country code:  39
 Area code:     415
 Phone number:  8675555
 Type:          B
 Year:          2012
There are duplicate digits in this phone number!!


code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

//()
char openedP='('; //open (
char closedP=')'; //close )
//end ()

//dash
char dash='-';
//end dash

class PhoneNumber
{
int countryCode;
int areaCode;
int number;
char type;
int year;
public:
PhoneNumber()
{
countryCode = 43;
areaCode = 800;
number = 8675309;
type = 'H';
year = 1981;
}
PhoneNumber(int ccode, int acode, int num,char line,int yr)
{
countryCode = ccode;
areaCode = acode;
number = num;
type = line;
year = yr;

}
PhoneNumber(int num,char line = 'B')
{
number = num;
areaCode = 800;
year = 1981;
countryCode = 43;
type = line;
}
PhoneNumber(int acode, int num, char line = 'C')
{
countryCode = 43;
year = 1981;
areaCode = acode;
number = num;
type = line;

}
void setCountry(int ccode)
{
ccode = countryCode;
}
void setArea(int acode)
{
acode = areaCode;
}
void setType(char line)
{
type = line;
}
void setYear(int yr)
{
year = yr;
}
int getCountry() const
{
return countryCode;
}
int getNumber() const
{
return number;
}
int getArea() const
{
return areaCode;
}
char getType() const
{
return type;
}
void printNumber(ostream& out) const //Prints Areacode & Phone Number
{
cout<<"The phone number is: \n";
cout<<openedP<<areaCode<<closedP<<number<<endl;
cout<<endl;
}
void printPhoneNumberStats(ostream& out) const // prints all phone information
{
cout<<"Printing phone number stats!\n";
cout<<" Country code: "<<countryCode<<endl;
cout<<" Area code:    "<<areaCode<<endl;
cout<<" Phone number: "<<number<<endl;
cout<<" Type:         "<<type<<endl;
cout<<" Year:         "<<year<<endl;
cout<<endl;
}
};
int main()
{
    char q; //stop from quitting
    PhoneNumber firstNum;
    PhoneNumber secondNum(39, 415, 8675555, 'B', 2012);
    PhoneNumber thirdNum(1234567);
    PhoneNumber fourthNum(1234566, 'C');
    PhoneNumber fifthNum(925, 4392181);
    PhoneNumber sixthNum(925, 5512346, 'H');

    firstNum.printNumber(cout);
    firstNum.printPhoneNumberStats(cout);
    secondNum.printNumber(cout);
    secondNum.printPhoneNumberStats(cout);
    thirdNum.printNumber(cout);
    thirdNum.printPhoneNumberStats(cout);
    fourthNum.printNumber(cout);
    fourthNum.printPhoneNumberStats(cout);
    fifthNum.printNumber(cout);
    fifthNum.printPhoneNumberStats(cout);
    sixthNum.printNumber(cout);
    sixthNum.printPhoneNumberStats(cout);
cin>>q;
  return 0;
}
You can do two things to get the hyphen in there:

1. Store the phone number as a string instead of as an int.

2. Split up your cout:

cout << "Phone number: " << number/10000 <<'-'<< number%10000 <<endl;
okay I used your 2nd option and it worked. Now I just need to display if the phone number had double digits.
Topic archived. No new replies allowed.