bpascal123
6/6/2011 1:00:00 AM
Thanks for this, this tells me I have to keep close to the basics of
the language.
The initial code is below. As you can see, it's a cpp code. Maybe I
should post this on the cpp discussion but I have already posted a
discussion about the code here, it makes the thread really look like a
thread. And for most here i guess, dealing with this is a little
boring recreation...
On the cpp code below, if I enter a number out of the positive integer
range, the code code goes into an infinite loop. I'd like to
understand the reason as there are validation controls that should
prevent this infinite loop.
#include "std_lib_facilities.h"
int main()
{
int val1 = 0 ;
int val2 = 0 ;
int stop = 0 ;
string cont = " " ;
bool ok = 1 ;
//cout << "\nValeur int de stop : " << stop ;
//cout << "\nValeur char de stop : " << sign ;
while (cont != "|")
{
cout << "\nEntrez 2 nombres (compris entre 0 et 65,536) : \n" ;
cin >> val1 >> val2 ;
if ( ((val1 >= 0) && (val1 < 65536)) && ((val2 >= 0) && (val2 <
65536)) )
ok = 1 ;
else
ok = 0 ;
while (!ok)
{
cout << "\nSaisie en dehors des limites\n" ;
cout << "\nEntrez 2 nombres (compris entre 0 et 65,536) : \n" ;
cin >> val1 >> val2 ;
if ( ((val1 >= 0) && (val1 < 65536)) && ((val2 >= 0) && (val2 <
65536)) )
ok = 1 ;
else
ok = 0 ;
}
cout << "\nvaleur 1 : " << val1 << "\tvaleur 2 : " << val2 << "\n" ;
cout << "\nAppuyer sur une touche : \n" ;
cin >> cont ;
}
cout << "\nFin\n" ;
cout << "\n\n" ;
system("pause") ;
return 0 ;
}
I don't know if this is again something I have dealt some time ago
that I am missing...
Thanks for your help,
Pascal