Ignoring spaces

I wrote this program to determine if you are calling the U.S. based on the area code you dial. I've only got three up for trials. I'm trying to make it ignore spaces and dashes, but can't figure out how to without the program staying at the first input.

EDIT: I've rewritten the code to accept the three parts of the number as different inputs, and it now works. Is there a shorter way to achieve this?

#include <iostream>
#include <string>
using namespace std;

#include <iostream>
#include <string>
using namespace std;

int main (void)
{
int statesphone1 =917;
int statesphone2 = 716;
int statesphone3 = 512;
int phone;
int phone2;
int area;

cout << "Enter the area code and phone number now: " << endl;
cin >> area;
cin >> phone;
cin >> phone2;
if (area == statesphone1 || area == statesphone2 || area == statesphone3)
cout << "1-(688)-466-3-" << area << "-" << phone << "-" << phone2 << " | number dialed." << endl;

else if (area != statesphone1 || area != statesphone2 || area != statesphone3)
cout << area << "-" << phone << "-" << phone2 << endl;
return 0;

}
Last edited on
There isn't anything shorter, but if you ever need to process input, it might be best to getline the whole line, check each character, and if it's a digit, append it to a new string.
Okay, thanks. I'm just glad it works. I'm also trying to figure out how to put in more area codes without having dozens of 'int's. Should I use an array or class, or is there another way?
An array and a for loop.
Thanks, I'll give it a try.
You don't actually need that second if there... the else does it just fine, besides which you would have wanted to use && instead of || anyway...
how would the for loop work?
For input, just for( int i = 0; i < number_of_codes; i++ ) cin >> area_code[i];. Same for output.
What else do you want to do with each code?
Topic archived. No new replies allowed.