I have to store ssn as an int but print it with dashes 000-00-0000. How do I go about with this. I know you can use substring for strings but using int is new.
Any help is appreciated.
Ex:
class student
{
private:
string FIRST;
string MIDDLE;
string LAST;
int SSN;
public:
******
};
Hopefully, you're not using actual SS numbers, as it's a very bad idea, as LB says. But, if it's just for the program, and the numbers are not going to be stored, or saved in a file, you could go this route. Instead of an int, use char SSN[10];
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
using std::endl;
using std::cout;
int main()
{
char SSN[10] = "123456789"; // or fill it with a user input
cout << "SS number : ";
for (int x = 0; x < 9; x++)
{
if (x == 3 || x == 5)
cout << "-";
cout << SSN[x];
}
cout << endl << endl;
return 0;
}