hey guys, I need to take a phone number in in the format of "(555)555-5555"
This is how I did it:
When it doesn't match It goes to an error that says the following in Dev-C++Code:void CustomerData::setPhone(string temp)throw (string){ bool correct[10] = {false}; char possible[10] = {'1','2','3','4','5','6','7','8','9','0'}; bool good = true; for(int i = 0; i<10; i++){ if(temp.at(1)==possible[i]) correct[0] = true; if(temp.at(2)==possible[i]) correct[1] = true; if(temp.at(3)==possible[i]) correct[2] = true; if(temp.at(5)==possible[i]) correct[3] = true; if(temp.at(6)==possible[i]) correct[4] = true; if(temp.at(7)==possible[i]) correct[5] = true; if(temp.at(9)==possible[i]) correct[6] = true; if(temp.at(10)==possible[i]) correct[7] = true; if(temp.at(11)==possible[i]) correct[8] = true; if(temp.at(12)==possible[i]) correct[9] = false; } for(int i = 0; i < 10; i++){ cout<<correct[i]<<endl; if(correct[i]!= true) good = false; } if(temp.length() != 13 || temp.at(0) != '(' || temp.at(4) != ')' || temp.at(8) != '-' || good == false) throw string("Incorrectly Formatted Phone Number\n"); else phone = temp; }
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Here's my main(where I catch the thrown strings):
Any help greatly appreciated!Code:#include <fstream> #include "CustomerData.h" #include "CDRecord.h" using namespace std; int main(int argc, char *argv[]) { //create the file streams and load the files into them fstream file; fstream ofile; file.open("testFile.txt", ios::in); ofile.open("newfile.txt", ios::out); //Create the objects to be used for the input and output CustomerData cd; CDRecord cdr; //read in the file and add the information to the //CDRecord object by means of adding the file information //to a CustomerData object and adding it to the CDRecord //object while(!file.eof()){ try{ file>>cd; cdr+cd; }catch(string m){ cout<<m; break; } } //Write all the information to the output file ofile<<cdr; system("PAUSE"); return EXIT_SUCCESS; }


Reply With Quote



Bookmarks