|
-
Jan 6th, 2006, 04:04 AM
#1
Thread Starter
New Member
Re: If else- letters not allowed
 Originally Posted by CornedBee
Well? What's the expected result, the actual result? Any compile errors (for example from that extra logical OR in the if)?
As it is now, the else will be only executed if the number is between 1 and 50 inclusive. Isn't that what you want?
Yes, i rectify what i have written. There should not be any extra ||. I forgot to erase it. What i was doing was the following:
if(value < 1 || value > 50|| (char) value)
So,when i type letters, the characters should not be accepted. Unfortunately, this does not work.
There is no compile errors if the extra|| is taken out.
But suppose by mistake instead of typing values between 1 and 50 I type a letter. Then, the program crashes.
So i want some flexibility so that no letters are allowed. Only the values between 1 and 50. Is that possible?
-
Jan 6th, 2006, 07:39 AM
#2
Re: If else- letters not allowed
Hello,
Welcome to Forums 
what you are trying to accomplish can be acheived by playing with ASCII values but i won't suggest you for this. you may try reversing the if-then-else statement. like:
Code:
scanf("%lf",&value);
if(value > 1 && value < 50 )
{
//do your stuff here
}
else
{
printf("not allowed\n");
printf("Please choose value between 0 and 50");
}
hope it helps you.
-
Jan 6th, 2006, 03:40 PM
#3
Thread Starter
New Member
Re: If else- letters not allowed
 Originally Posted by Harsh Gupta
Hello,
Welcome to Forums
what you are trying to accomplish can be acheived by playing with ASCII values but i won't suggest you for this. you may try reversing the if-then-else statement. like:
Code:
scanf("%lf",&value);
if(value > 1 && value < 50 )
{
//do your stuff here
}
else
{
printf("not allowed\n");
printf("Please choose value between 0 and 50");
}
hope it helps you.
No this does not help. A lot of ' Not allowed' appears on the window when i typed a letter.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|