Infinite Loop after cin help

Nov 9, 2012 at 11:09pm
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 Nov 12, 2012 at 8:42pm
Nov 10, 2012 at 2:07am
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?
Nov 10, 2012 at 11:03pm
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 Nov 12, 2012 at 8:42pm
Nov 11, 2012 at 6:00pm
Seems the problem is with the line
1
2
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.
Nov 12, 2012 at 8:09pm
Been a couple of days and still can't seem to get this code to work. Was wondering if anyone had any tips.
Nov 12, 2012 at 8:13pm
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 Nov 12, 2012 at 8:23pm
Nov 12, 2012 at 8:16pm
Thanks that did the tricke, didn't think about clearing the stream! :-)
Nov 12, 2012 at 8:23pm
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.
Nov 12, 2012 at 8:34pm
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.