loop troubles

this loop I have in the main function wont break out even when it's control varriable is the correct value when the loop checks it (used debugger to check it)
could someone please point out what I'm doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  #include <iostream>
using namespace std;

int ReadInt(unsigned int &Num1);
void main()
{
	unsigned int Number1=0, Error;
	char Continue;
	
	do
	{
		cout<<"Please enter a number: ";
		Error=ReadInt(Number1);
		if (Error==2)
			cout<<"That Number is too big, please use a smaller number."<<endl;
		else if (Error==1)
			cout<<"That is not a Number."<<endl;
		else
			cout<<"Was this your number: "<<Number1<<endl;
		cout<<"If you want to stop please enter n."<<endl;
		cin>>Continue;
		cin.ignore(100, '\n');}
	while(Continue!='n'||Continue!='N');
}
int ReadInt(unsigned int &Num1)
{
	char Ch;
	Num1=0;
	cin.get(Ch);
	while(isspace(Ch))
		cin.get(Ch);
	if(isalpha(Ch))
		return 1;
	while(isdigit(Ch))
	{
		Num1=(Num1*10)+(Ch-'0');
		cin.get(Ch);
	}
	if(unsigned long int (Num1)>65535)
		return 2;
	else
		return 0;
}
Last edited on
Your logic is wrong. Think about what 'or' means.
One or both of your conditions will always be true.
Try 'and' instead. while(Continue!='n'&&Continue!='N');
I see now, I was thinking logical or meant if one or the other were true that it would stop, but i see what your saying. thanks for the help.
Topic archived. No new replies allowed.