Topic
• 3 replies
• Latest Post - ‏2008-01-23T23:48:20Z by SystemAdmin
210 Posts

# Pinned topic User Validation code help please!!!

‏2006-10-03T13:14:34Z |
hi everyone, i'm a college student and i have to write up a body mass index code, i've got the body mass index code written and suprisingly it works but i cannot figure out how to get user validation code in there so that a box pops and tells the user their input is invalid when they dont enter their height and weight properly. this is what i'm trying to put together.

if (pounds < 1) || (pounds > 1000);
{
if (inches < 12) || (inches > 100);
{

else

System.out.println("\t\t\tInput values are not in an acceptable range");
}

i know something is missing or maybe even the whole deal is totally wrong i dont know but its giving me a great big headache. can someone help me please!! i'd really appreciate it.
Updated on 2008-01-23T23:48:20Z at 2008-01-23T23:48:20Z by SystemAdmin
210 Posts

#### Re: User Validation code help please!!!

‏2006-12-13T22:41:21Z
writing:
if (pounds < 1 || pounds > 1000);
is effectivly:
if (pounds < 1) || (pounds > 1000) { }

which is obviously not what your after.
you have some problems with your syntax.

assuming you want only values of pounts 1->999 and inches 12->99.
change it all to:
if (pounds < 1 || pounds > 1000 || inches < 12 || inches > 100) {
System.out.println("\t\t\tInput values are not in an acceptable range");
}
210 Posts

#### Re: User Validation code help please!!!

‏2007-12-27T16:47:40Z
writing:
if (pounds < 1 || pounds > 1000);
is effectivly:
if (pounds < 1) || (pounds > 1000) { }

which is obviously not what your after.
you have some problems with your syntax.

assuming you want only values of pounts 1->999 and inches 12->99.
change it all to:
if (pounds < 1 || pounds > 1000 || inches < 12 || inches > 100) {
System.out.println("\t\t\tInput values are not in an acceptable range");
}
hi
try using this
if ((pounds < 1 || pounds > 1000) && (inches < 12 || inches > 100)) {
System.out.println("\t\t\tInput values are not in an acceptable range");
}

thanks
Rakesh
210 Posts

#### Re: User Validation code help please!!!

‏2008-01-23T23:48:20Z
hi
try using this
if ((pounds < 1 || pounds > 1000) && (inches < 12 || inches > 100)) {
System.out.println("\t\t\tInput values are not in an acceptable range");
}

thanks
Rakesh
wouldnt that mean that if pounds were 50,000 (which should not be allowed), as long as the inches is correct, the output wont be shown?

(50,000 < 1 || 50,000 > 1000) = true
(20 < 12 || 20 > 100) = false

true && false = false, meaning no error message is shown, even though the pounds is invalid.