Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is Integer Usage Example #217

Open
wants to merge 1 commit into
base: usage-examples
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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!");
Original file line number Diff line number Diff line change
@@ -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!");

}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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!")
Original file line number Diff line number Diff line change
@@ -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.