diff --git a/public/usage-examples/utilities/is_integer/is_integer-1-validator-oop.cs b/public/usage-examples/utilities/is_integer/is_integer-1-validator-oop.cs new file mode 100644 index 00000000..1261e173 --- /dev/null +++ b/public/usage-examples/utilities/is_integer/is_integer-1-validator-oop.cs @@ -0,0 +1,26 @@ +using static SplashKitSDK.SplashKit; + +WriteLine("Welcome to the Integer Validation Checker!"); + +bool validInput = false; + +// Loop until the user enters a valid integer +while (!validInput) +{ + WriteLine("Please enter a valid integer:"); + string input = ReadLine(); + + // Check if the input is a valid integer + if (IsInteger(input)) + { + int number = ConvertToInteger(input); // Convert input to integer + WriteLine($"Great! You've entered a valid integer: {number}"); + validInput = true; // Exit loop on valid input + } + else + { + WriteLine("Oops! That's not a valid integer. Please try again."); + } +} + +WriteLine("Thank you for using the Integer Validation Checker!"); diff --git a/public/usage-examples/utilities/is_integer/is_integer-1-validator-top-level.cs b/public/usage-examples/utilities/is_integer/is_integer-1-validator-top-level.cs new file mode 100644 index 00000000..74d67bba --- /dev/null +++ b/public/usage-examples/utilities/is_integer/is_integer-1-validator-top-level.cs @@ -0,0 +1,36 @@ +using SplashKitSDK; + +namespace Program +{ + public class Program + { + public static void Main() + { + SplashKit.WriteLine("Welcome to the Integer Validation Checker!"); + + bool validInput = false; + + // Loop until the user enters a valid integer + while (!validInput) + { + SplashKit.WriteLine("Please enter a valid integer:"); + string input = SplashKit.ReadLine(); + + // Check if the input is a valid integer + if (SplashKit.IsInteger(input)) + { + int number = SplashKit.ConvertToInteger(input); // Convert input to integer + SplashKit.WriteLine($"Great! You've entered a valid integer: {number}"); + validInput = true; // Exit loop on valid input + } + else + { + SplashKit.WriteLine("Oops! That's not a valid integer. Please try again."); + } + } + + SplashKit.WriteLine("Thank you for using the Integer Validation Checker!"); + + } + } +} \ No newline at end of file diff --git a/public/usage-examples/utilities/is_integer/is_integer-1-validator.cpp b/public/usage-examples/utilities/is_integer/is_integer-1-validator.cpp new file mode 100644 index 00000000..46ed1ed0 --- /dev/null +++ b/public/usage-examples/utilities/is_integer/is_integer-1-validator.cpp @@ -0,0 +1,32 @@ +#include "splashkit.h" + +int main() +{ + write_line("Welcome to the Integer Validation Checker!"); + + string input; + bool valid_input = false; + + // Loop until the user enters a valid integer + while (!valid_input) + { + write_line("Please enter a valid integer:"); + input = read_line(); + + // Check if the input is a valid integer + if (is_integer(input)) + { + int number = convert_to_integer(input); // Convert input to integer + write_line("Great! You've entered a valid integer: " + std::to_string(number)); + valid_input = true; // Exit loop on valid input + } + else + { + write_line("Oops! That's not a valid integer. Please try again."); + } + } + + write_line("Thank you for using the Integer Validation Checker!"); + + return 0; +} diff --git a/public/usage-examples/utilities/is_integer/is_integer-1-validator.png b/public/usage-examples/utilities/is_integer/is_integer-1-validator.png new file mode 100644 index 00000000..d5c62012 Binary files /dev/null and b/public/usage-examples/utilities/is_integer/is_integer-1-validator.png differ diff --git a/public/usage-examples/utilities/is_integer/is_integer-1-validator.py b/public/usage-examples/utilities/is_integer/is_integer-1-validator.py new file mode 100644 index 00000000..39d6dece --- /dev/null +++ b/public/usage-examples/utilities/is_integer/is_integer-1-validator.py @@ -0,0 +1,20 @@ +from splashkit import * + +write_line("Welcome to the Integer Validation Checker!") + +valid_input = False + +# Loop until the user enters a valid integer +while not valid_input: + write_line("Please enter a valid integer:") + input_value = read_line() + + # Check if the input is a valid integer + if is_integer(input_value): + number = convert_to_integer(input_value) # Convert input to integer + write_line(f"Great! You've entered a valid integer: {number}") + valid_input = True # Exit loop on valid input + else: + write_line("Oops! That's not a valid integer. Please try again.") + +write_line("Thank you for using the Integer Validation Checker!") diff --git a/public/usage-examples/utilities/is_integer/is_integer-1-validator.txt b/public/usage-examples/utilities/is_integer/is_integer-1-validator.txt new file mode 100644 index 00000000..0dda42dc --- /dev/null +++ b/public/usage-examples/utilities/is_integer/is_integer-1-validator.txt @@ -0,0 +1,3 @@ +### Input Validation of Integers + +The following code shows examples of using [is integer](/api/utilities/#is-integer), which asks the user to enter an integer and then checks if the input is an integer, if it is not an integer, it will ask the user to enter an integer again. \ No newline at end of file