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?
#include <iostream>
usingnamespace std;
int ReadInt(unsignedint &Num1);
void main()
{
unsignedint 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;
elseif (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(unsignedint &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(unsignedlongint (Num1)>65535)
return 2;
elsereturn 0;
}
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');