Conditional statement that will prevent users from imputing

  • Thread starter Thread starter GreenPrint
  • Start date Start date
  • Tags Tags
    Conditional
AI Thread Summary
A user seeks a conditional statement to ensure only integer inputs are accepted in a loop, displaying an error message for invalid entries. The discussion highlights the need for a solution that prompts users repeatedly until a valid integer is entered. Suggestions include utilizing functions like INT() or floor() to validate input. The conversation notes the lack of built-in functions in many programming languages to enforce input restrictions effectively. Ultimately, the focus remains on finding a reliable method to filter out non-integer inputs.
GreenPrint
Messages
1,186
Reaction score
0

Homework Statement



I was wondering if anyone knows of a conditional statement that will prevent users from imputing non integer inputs.

like for example
z=0
while z<1
x=input('Enter Something')
if SOME MAGICAL CONDITIONAL STATEMENT
disp('You entered a invalid entry. Please try again.')
else
z=1;
end
end

I hope you get what I'm trying to do. In a loop prompt a user to enter a number. If the user enters a number like 5.5 I would like the message to come up 'You entered a invalid entry. Please try again.' by using some conditional statement

anyone got any ideas?

Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org


Does the computer language that you're using have INT() or floor() functions?
 


It's too bad most programming languages don't have a built-in function which tases users who don't follow directions.
 

Similar threads

Replies
6
Views
3K
Replies
10
Views
2K
Replies
3
Views
1K
Replies
9
Views
4K
Replies
2
Views
3K
Replies
4
Views
2K
Replies
4
Views
5K
Back
Top