Aug 17, 2011 at 2:06pm UTC
I wrote this code to automatically call the U.S. based on the area code of the phone number, but can't figure out what the error means.
>#include <iostream>
>using namespace std;
>
>int main (void)
>{
> int statesphone1 =917;
> int statesphone2 = 716;
> int statesphone3 = 512;
> int phone;
>
>cout << "Enter phone number now: " << endl;
> cin >> phone;
> if (phone == statesphone1 || statesphone2 || statesphone3)
> cout << "1-(688)-466-3-" << phone << " | number dialed." << endl;
>
> else if (phone != statesphone1 || statesphone2 || statesphone3)
> cout << phone << endl;
>return 0;
>}
Any help would be appreciated.
Aug 18, 2011 at 8:29am UTC
Thanks coder. That worked perfectly.
I am now having a problem with getting the program to ignore spaces and dashes.
#include <iostream>
using namespace std;
int main (void)
{
int statesphone1 =917;
int statesphone2 = 716;
int statesphone3 = 512;
int phone;
cout << "Enter phone number now: " << endl;
cin >> phone;
if (phone == statesphone1 || phone == statesphone2 || phone == statesphone3)
cout << "1-(688)-466-3-" << phone << " | number dialed." << endl;
else if (phone != statesphone1 || phone != statesphone2 || phone != statesphone3)
cout << phone << endl;
return 0;
}
As before, any help would be appreciated.
Aug 19, 2011 at 11:27am UTC
cin >> phone;
does not allow spaces and dashes. Or do you mean that you want to enter that then you need to string phone;