Infinite Loop after cin help

Below is a code fragment that I'm having trouble with. For some reason I get an infinite loop after entering the telephone number into the struct variable that is an int. I think it has something to do with alternating between getline and cin but even if I add the cin.ignore is still doesn't fix the problem. Was wondering if anyone notices anything that might help:

Last edited on
I tested it, but I took [count].name out and all the other [count] out to test it and it worked fine. Can I see more code?
Here is what I have so far. It's inside a switch statement. Well the [count] is there so that the user will step through the struct entering the information that is requested. Here some more code to see what I am doing wrong:

Last edited on
Seems the problem is with the line
cout << "Telephone number: " << endl;
cin >> customerAcc[count].tele;

If I enter one digit less than a full phone number then it works fine. But if I enter a whole phone number like 7078031940 then it goes into an infinite loop. Still trying to figure this out its pretty weird.
Been a couple of days and still can't seem to get this code to work. Was wondering if anyone had any tips.
I'm not sure whether this will work. After an error has occurred on a stream, you can clear the flags with clear(). Thus cin.clear(); may help.
Last edited on
Thanks that did the tricke, didn't think about clearing the stream! :-)
The reason for the error is that 7078031940 requires 33 bits to store as an integer.
Thus it will probably need to be handled as a string, or as a type long long which is (at least) 64 bits.
Ah yea completely overlooked that fact. Thanks again, got the program running. I'll definitely remember this for next time hehe.
Topic archived. No new replies allowed.