Conditional statement that will prevent users from imputing

  • Thread starter Thread starter GreenPrint
  • Start date Start date
  • Tags Tags
    Conditional
Click For Summary
SUMMARY

The discussion focuses on implementing a conditional statement in programming to prevent users from inputting non-integer values. The user seeks a solution to prompt for input repeatedly until a valid integer is entered, specifically mentioning the need for feedback when a decimal or invalid entry is made. Suggestions include utilizing functions like INT() or floor() to validate input. The conversation highlights the importance of input validation in user interfaces.

PREREQUISITES
  • Understanding of basic programming concepts, including loops and conditional statements.
  • Familiarity with input functions in programming languages.
  • Knowledge of data types, specifically integers and their validation.
  • Experience with error handling and user feedback mechanisms in code.
NEXT STEPS
  • Research input validation techniques in Python using the int() function.
  • Learn about error handling in JavaScript with try-catch statements.
  • Explore user input handling in MATLAB, focusing on input validation methods.
  • Investigate best practices for creating user-friendly prompts in command-line applications.
USEFUL FOR

Programmers, software developers, and anyone involved in creating user interfaces that require robust input validation to enhance user experience and prevent errors.

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 ·
Replies
6
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
22
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
8
Views
7K
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K