Compare commits

...

5 commits

Author SHA1 Message Date
lily
51e7266911 Actually add the bool check this time
Some checks failed
Create Release on Push / build_and_release_linux (push) Has been cancelled
Create Release on Push / build_and_upload_windows (push) Has been cancelled
2025-10-06 06:58:41 +11:00
lily
34a6070190 Revert "Replace IsValidNumber with IsBool for int/float query"
This reverts commit 7ad41ef827.
2025-10-06 06:55:50 +11:00
lily
a950c86624 changed 2025-10-06 06:54:16 +11:00
lily
7ad41ef827 Replace IsValidNumber with IsBool for int/float query 2025-10-05 23:56:07 +11:00
lily
e1e16a1566 Add isbool function 2025-10-05 23:50:29 +11:00

View file

@ -5,6 +5,21 @@
#include <stdlib.h>
#include <string.h>
int isbool(char entered []) {
int valid = 1;
for (int i = 0; i < strlen(entered); i++) {
switch (entered[i]) {
case '0':
case '1':
break;
default:
valid = 0;
break;
}
}
return valid;
}
int isvalidnumber(char entered []) {
int valid = 1;
for (int i = 0; i < strlen(entered); i++) {
@ -44,7 +59,7 @@ int main(void) {
printf ("Hello %s!\nThis is a game written for AgnoxGD.\nWould you like to see a tutorial\nType 1 for no, or 0 for yes.\n", username);
scanf("%s", input);
if (isvalidnumber(input)) {
if (isbool(input)) {
sscanf(input, "%d", &tempInput);
tutorial = tempInput;
} else {
@ -60,7 +75,7 @@ int main(void) {
printf ("\nWould you like your accuracy as a float or as an int? Type 0 for float or 1 for int.\n");
scanf ("%s", input);
if (isvalidnumber(input)) {
if (isbool(input)) {
sscanf(input, "%d", &accuracytype);
} else {
printf ("Error! An invalid character was entered.\n");