From cf021f6c7b7e7129ee7acd5d481565fb0c51aa5f Mon Sep 17 00:00:00 2001 From: nrezmerski <108252649+nrezmerski@users.noreply.github.com> Date: Tue, 24 Oct 2023 08:03:13 -0500 Subject: [PATCH 1/4] Create hello.c Initial commit of ANSI C version of "hello.bas" --- .../45_Hello/ANSI_C/hello.c | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 00_Alternate_Languages/45_Hello/ANSI_C/hello.c diff --git a/00_Alternate_Languages/45_Hello/ANSI_C/hello.c b/00_Alternate_Languages/45_Hello/ANSI_C/hello.c new file mode 100644 index 000000000..6d6eae786 --- /dev/null +++ b/00_Alternate_Languages/45_Hello/ANSI_C/hello.c @@ -0,0 +1,164 @@ +#include +#include + +#define TRUE 1 +#define FALSE 0 +#define MAX_INPUT_LENGTH 80 + +void tab(int number_of_spaces); +void get_input(char *input_buffer); +int strings_match(char *string1, char *string2); + +int main() { + int done = FALSE; + int paid = FALSE; + int maybe_more, sure; + + char name[MAX_INPUT_LENGTH]; + char reply[MAX_INPUT_LENGTH]; + + tab(33); + printf("HELLO\n"); + tab(15); + printf("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n"); + printf("\n\n\n"); + printf("HELLO. MY NAME IS CREATIVE COMPUTER.\n"); + printf("\n\nWHAT'S YOUR NAME "); + get_input(name); + printf("\nHI THERE, %s, ARE YOU ENJOYING YOURSELF HERE ", name); + + get_input(reply); + while (!strings_match(reply, "YES") && !strings_match(reply, "NO")) { + printf("%s, I DON'T UNDERSTAND YOUR ANSWER OF '%s'.\n", name, reply); + printf("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE "); + get_input(reply); + } + + if (strings_match(reply, "YES")) { + printf("I'M GLAD TO HEAR THAT, %s.\n", name); + } + else { + printf("OH, I'M SORRY TO HEAR THAT, %s. MAYBE WE CAN " + "BRIGHTEN UP YOUR VISIT A BIT.\n", name); + } + + printf("\nSAY, %s, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT " + "THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO " + "YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB) ", name); + + while (!done) { + get_input(reply); + + if (strings_match(reply, "JOB")) { + printf("I CAN SYMPATHIZE WITH YOU %s. I HAVE TO WORK " + "VERY LONG HOURS FOR NO PAY -- AND SOME OF MY BOSSES " + "REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, %s, IS TO " + "OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n\n", name, name); + } + + else if (strings_match(reply, "MONEY")) { + printf("SORRY, %s, I'M BROKE TOO. WHY DON'T YOU SELL " + "ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING " + "SO YOU WON'T NEED SO MUCH MONEY?\n\n", name); + } + + else if (strings_match(reply, "HEALTH")) { + printf("MY ADVICE TO YOU %s IS:\n", name); + printf(" 1. TAKE TWO ASPRIN\n"); + printf(" 2. DRINK PLENTY OF FLUIDS (ORANGE JUICE, NOT BEER!)\n"); + printf(" 3. GO TO BED (ALONE)\n\n"); + } + + else if (strings_match(reply, "SEX")) { + printf("IS YOUR PROBLEM TOO MUCH OR TOO LITTLE "); + + sure = FALSE; + while (!sure) { + get_input(reply); + if (strings_match(reply, "TOO MUCH")) { + printf("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!\n"); + printf("IF IT BOTHERS YOU, %s, TAKE A COLD SHOWER.\n\n", name); + sure = TRUE; + } + else if (strings_match(reply, "TOO LITTLE")) { + printf("WHY ARE YOU HERE IN SUFFERN, %s? YOU SHOULD BE " + "IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME " + "REAL ACTION.\n\n", name); + sure = TRUE; + } + else { + printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION " + "WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name); + } + } + } + + else { // not one of the prescribed categories + printf("OH, %s, YOUR ANSWER OF '%s' IS GREEK TO ME.\n\n", name, reply); + } + + printf("ANY MORE PROBLEMS YOU WANT SOLVED, %s ", name); + + maybe_more = TRUE; + while (maybe_more) { + get_input(reply); + if (strings_match(reply, "NO")) { + done = TRUE; + maybe_more = FALSE; + } + else if (strings_match(reply, "YES")) { + printf("WHAT KIND (SEX, MONEY, HEALTH, JOB) "); + maybe_more = FALSE; + } + else { + printf("JUST A SIMPLE 'YES' OR 'NO' PLEASE, %s. ", name); + } + } // no further questions + } // end of 'not done' loop + + printf("\nTHAT WILL BE $5.00 FOR THE ADVICE, %s.\n", name); + printf("PLEASE LEAVE THE MONEY ON THE TERMINAL.\n"); + // pause a few seconds + printf("\n\n\nDID YOU LEAVE THE MONEY "); + get_input(reply); + while (!paid) { + if (strings_match(reply, "YES")) { + printf("HEY, %s??? YOU LEFT NO MONEY AT ALL!\n", name); + printf("YOU ARE CHEATING ME OUT OF MY HARD-EARNED LIVING.\n"); + printf("\nWHAT A RIP OFF, %s!!!\n", name); + printf("TAKE A WALK, %s.\n\n", name); + paid = TRUE; + } + else if (strings_match(reply, "NO")) { + printf("THAT'S HONEST, %s, BUT HOW DO YOU EXPECT " + "ME TO GO ON WITH MY PSYCHOLOGY STUDIES IF MY PATIENTS " + "DON'T PAY THEIR BILLS?\n\n", name); + printf("NICE MEETING YOU, %s, HAVE A NICE DAY.\n", name); + paid = TRUE; + } + else { + printf("YOUR ANSWER OF '%s' CONFUSES ME, %s.\n", reply, name); + printf("PLEASE RESPOND WITH 'YES' OR 'NO'.\n"); + } + } +} + + +void tab(int number_of_spaces) { + for (int i=0; i < number_of_spaces; i++) + putchar(' '); +} + + +void get_input(char *input_buffer) { + fgets(input_buffer, MAX_INPUT_LENGTH - 1, stdin); + input_buffer[strcspn(input_buffer, "\n")] = '\0'; // trim the trailing line break +} + + +int strings_match(char *string1, char *string2) { + if (strncmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0) + return FALSE; + else // strings match, at least within maximum input line length + return TRUE; +} From 5293edcd89eaaf37117056abb35f0b13de2eefaa Mon Sep 17 00:00:00 2001 From: nrezmerski <108252649+nrezmerski@users.noreply.github.com> Date: Tue, 24 Oct 2023 15:08:24 -0500 Subject: [PATCH 2/4] Update hello.c Fix mixed spaces/tabs indentation --- .../45_Hello/ANSI_C/hello.c | 60 +++++++------------ 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/00_Alternate_Languages/45_Hello/ANSI_C/hello.c b/00_Alternate_Languages/45_Hello/ANSI_C/hello.c index 6d6eae786..7e93e3c5a 100644 --- a/00_Alternate_Languages/45_Hello/ANSI_C/hello.c +++ b/00_Alternate_Languages/45_Hello/ANSI_C/hello.c @@ -1,22 +1,17 @@ #include #include - #define TRUE 1 #define FALSE 0 #define MAX_INPUT_LENGTH 80 - void tab(int number_of_spaces); void get_input(char *input_buffer); int strings_match(char *string1, char *string2); - int main() { int done = FALSE; int paid = FALSE; int maybe_more, sure; - char name[MAX_INPUT_LENGTH]; char reply[MAX_INPUT_LENGTH]; - tab(33); printf("HELLO\n"); tab(15); @@ -26,14 +21,12 @@ int main() { printf("\n\nWHAT'S YOUR NAME "); get_input(name); printf("\nHI THERE, %s, ARE YOU ENJOYING YOURSELF HERE ", name); - get_input(reply); while (!strings_match(reply, "YES") && !strings_match(reply, "NO")) { printf("%s, I DON'T UNDERSTAND YOUR ANSWER OF '%s'.\n", name, reply); printf("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE "); get_input(reply); } - if (strings_match(reply, "YES")) { printf("I'M GLAD TO HEAR THAT, %s.\n", name); } @@ -41,11 +34,9 @@ int main() { printf("OH, I'M SORRY TO HEAR THAT, %s. MAYBE WE CAN " "BRIGHTEN UP YOUR VISIT A BIT.\n", name); } - printf("\nSAY, %s, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT " "THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO " "YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB) ", name); - while (!done) { get_input(reply); @@ -55,7 +46,6 @@ int main() { "REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, %s, IS TO " "OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n\n", name, name); } - else if (strings_match(reply, "MONEY")) { printf("SORRY, %s, I'M BROKE TOO. WHY DON'T YOU SELL " "ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING " @@ -74,23 +64,23 @@ int main() { sure = FALSE; while (!sure) { - get_input(reply); - if (strings_match(reply, "TOO MUCH")) { - printf("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!\n"); - printf("IF IT BOTHERS YOU, %s, TAKE A COLD SHOWER.\n\n", name); - sure = TRUE; - } - else if (strings_match(reply, "TOO LITTLE")) { - printf("WHY ARE YOU HERE IN SUFFERN, %s? YOU SHOULD BE " - "IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME " - "REAL ACTION.\n\n", name); - sure = TRUE; - } - else { - printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION " - "WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name); - } - } + get_input(reply); + if (strings_match(reply, "TOO MUCH")) { + printf("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!\n"); + printf("IF IT BOTHERS YOU, %s, TAKE A COLD SHOWER.\n\n", name); + sure = TRUE; + } + else if (strings_match(reply, "TOO LITTLE")) { + printf("WHY ARE YOU HERE IN SUFFERN, %s? YOU SHOULD BE " + "IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME " + "REAL ACTION.\n\n", name); + sure = TRUE; + } + else { + printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION " + "WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name); + } + } } else { // not one of the prescribed categories @@ -115,7 +105,6 @@ int main() { } } // no further questions } // end of 'not done' loop - printf("\nTHAT WILL BE $5.00 FOR THE ADVICE, %s.\n", name); printf("PLEASE LEAVE THE MONEY ON THE TERMINAL.\n"); // pause a few seconds @@ -142,23 +131,18 @@ int main() { } } } - - void tab(int number_of_spaces) { for (int i=0; i < number_of_spaces; i++) putchar(' '); } - - void get_input(char *input_buffer) { fgets(input_buffer, MAX_INPUT_LENGTH - 1, stdin); input_buffer[strcspn(input_buffer, "\n")] = '\0'; // trim the trailing line break } - - int strings_match(char *string1, char *string2) { - if (strncmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0) - return FALSE; - else // strings match, at least within maximum input line length - return TRUE; + if (strncasecmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0) + return FALSE; + else // strings match, at least within maximum input line length + return TRUE; } + From 63865151b6bfdfc48f1ccaf38c459d13f04d8956 Mon Sep 17 00:00:00 2001 From: nrezmerski <108252649+nrezmerski@users.noreply.github.com> Date: Tue, 24 Oct 2023 15:12:07 -0500 Subject: [PATCH 3/4] Update hello.c Replace 3-space indents with 4-space --- .../45_Hello/ANSI_C/hello.c | 270 ++++++++++-------- 1 file changed, 144 insertions(+), 126 deletions(-) diff --git a/00_Alternate_Languages/45_Hello/ANSI_C/hello.c b/00_Alternate_Languages/45_Hello/ANSI_C/hello.c index 7e93e3c5a..74b0275f2 100644 --- a/00_Alternate_Languages/45_Hello/ANSI_C/hello.c +++ b/00_Alternate_Languages/45_Hello/ANSI_C/hello.c @@ -1,148 +1,166 @@ #include #include + #define TRUE 1 #define FALSE 0 #define MAX_INPUT_LENGTH 80 + void tab(int number_of_spaces); void get_input(char *input_buffer); int strings_match(char *string1, char *string2); + int main() { - int done = FALSE; - int paid = FALSE; - int maybe_more, sure; - char name[MAX_INPUT_LENGTH]; - char reply[MAX_INPUT_LENGTH]; - tab(33); - printf("HELLO\n"); - tab(15); - printf("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n"); - printf("\n\n\n"); - printf("HELLO. MY NAME IS CREATIVE COMPUTER.\n"); - printf("\n\nWHAT'S YOUR NAME "); - get_input(name); - printf("\nHI THERE, %s, ARE YOU ENJOYING YOURSELF HERE ", name); - get_input(reply); - while (!strings_match(reply, "YES") && !strings_match(reply, "NO")) { - printf("%s, I DON'T UNDERSTAND YOUR ANSWER OF '%s'.\n", name, reply); - printf("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE "); - get_input(reply); - } - if (strings_match(reply, "YES")) { - printf("I'M GLAD TO HEAR THAT, %s.\n", name); - } - else { - printf("OH, I'M SORRY TO HEAR THAT, %s. MAYBE WE CAN " - "BRIGHTEN UP YOUR VISIT A BIT.\n", name); - } - printf("\nSAY, %s, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT " - "THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO " - "YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB) ", name); - while (!done) { - get_input(reply); - - if (strings_match(reply, "JOB")) { - printf("I CAN SYMPATHIZE WITH YOU %s. I HAVE TO WORK " - "VERY LONG HOURS FOR NO PAY -- AND SOME OF MY BOSSES " - "REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, %s, IS TO " - "OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n\n", name, name); - } - else if (strings_match(reply, "MONEY")) { - printf("SORRY, %s, I'M BROKE TOO. WHY DON'T YOU SELL " - "ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING " - "SO YOU WON'T NEED SO MUCH MONEY?\n\n", name); - } - - else if (strings_match(reply, "HEALTH")) { - printf("MY ADVICE TO YOU %s IS:\n", name); - printf(" 1. TAKE TWO ASPRIN\n"); - printf(" 2. DRINK PLENTY OF FLUIDS (ORANGE JUICE, NOT BEER!)\n"); - printf(" 3. GO TO BED (ALONE)\n\n"); - } - - else if (strings_match(reply, "SEX")) { - printf("IS YOUR PROBLEM TOO MUCH OR TOO LITTLE "); - - sure = FALSE; - while (!sure) { - get_input(reply); - if (strings_match(reply, "TOO MUCH")) { - printf("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!\n"); - printf("IF IT BOTHERS YOU, %s, TAKE A COLD SHOWER.\n\n", name); - sure = TRUE; + int done = FALSE; + int paid = FALSE; + int maybe_more, sure; + + char name[MAX_INPUT_LENGTH]; + char reply[MAX_INPUT_LENGTH]; + + tab(33); + printf("HELLO\n"); + tab(15); + printf("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n"); + printf("\n\n\n"); + printf("HELLO. MY NAME IS CREATIVE COMPUTER.\n"); + printf("\n\nWHAT'S YOUR NAME "); + get_input(name); + printf("\nHI THERE, %s, ARE YOU ENJOYING YOURSELF HERE ", name); + + get_input(reply); + while (!strings_match(reply, "YES") && !strings_match(reply, "NO")) { + printf("%s, I DON'T UNDERSTAND YOUR ANSWER OF '%s'.\n", name, reply); + printf("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE "); + get_input(reply); + } + + if (strings_match(reply, "YES")) { + printf("I'M GLAD TO HEAR THAT, %s.\n", name); + } + else { + printf("OH, I'M SORRY TO HEAR THAT, %s. MAYBE WE CAN " + "BRIGHTEN UP YOUR VISIT A BIT.\n", name); + } + + printf("\nSAY, %s, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT " + "THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO " + "YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB) ", name); + + while (!done) { + get_input(reply); + + if (strings_match(reply, "JOB")) { + printf("I CAN SYMPATHIZE WITH YOU %s. I HAVE TO WORK " + "VERY LONG HOURS FOR NO PAY -- AND SOME OF MY BOSSES " + "REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, %s, IS TO " + "OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n\n", name, name); + } + + else if (strings_match(reply, "MONEY")) { + printf("SORRY, %s, I'M BROKE TOO. WHY DON'T YOU SELL " + "ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING " + "SO YOU WON'T NEED SO MUCH MONEY?\n\n", name); + } + + else if (strings_match(reply, "HEALTH")) { + printf("MY ADVICE TO YOU %s IS:\n", name); + printf(" 1. TAKE TWO ASPRIN\n"); + printf(" 2. DRINK PLENTY OF FLUIDS (ORANGE JUICE, NOT BEER!)\n"); + printf(" 3. GO TO BED (ALONE)\n\n"); + } + + else if (strings_match(reply, "SEX")) { + printf("IS YOUR PROBLEM TOO MUCH OR TOO LITTLE "); + + sure = FALSE; + while (!sure) { + get_input(reply); + if (strings_match(reply, "TOO MUCH")) { + printf("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!\n"); + printf("IF IT BOTHERS YOU, %s, TAKE A COLD SHOWER.\n\n", name); + sure = TRUE; + } + else if (strings_match(reply, "TOO LITTLE")) { + printf("WHY ARE YOU HERE IN SUFFERN, %s? YOU SHOULD BE " + "IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME " + "REAL ACTION.\n\n", name); + sure = TRUE; + } + else { + printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION " + "WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name); + } + } + } + + else { // not one of the prescribed categories + printf("OH, %s, YOUR ANSWER OF '%s' IS GREEK TO ME.\n\n", name, reply); + } + + printf("ANY MORE PROBLEMS YOU WANT SOLVED, %s ", name); + + maybe_more = TRUE; + while (maybe_more) { + get_input(reply); + if (strings_match(reply, "NO")) { + done = TRUE; + maybe_more = FALSE; } - else if (strings_match(reply, "TOO LITTLE")) { - printf("WHY ARE YOU HERE IN SUFFERN, %s? YOU SHOULD BE " - "IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME " - "REAL ACTION.\n\n", name); - sure = TRUE; + else if (strings_match(reply, "YES")) { + printf("WHAT KIND (SEX, MONEY, HEALTH, JOB) "); + maybe_more = FALSE; } else { - printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION " - "WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name); + printf("JUST A SIMPLE 'YES' OR 'NO' PLEASE, %s. ", name); } - } - } - - else { // not one of the prescribed categories - printf("OH, %s, YOUR ANSWER OF '%s' IS GREEK TO ME.\n\n", name, reply); - } - - printf("ANY MORE PROBLEMS YOU WANT SOLVED, %s ", name); - - maybe_more = TRUE; - while (maybe_more) { - get_input(reply); - if (strings_match(reply, "NO")) { - done = TRUE; - maybe_more = FALSE; - } - else if (strings_match(reply, "YES")) { - printf("WHAT KIND (SEX, MONEY, HEALTH, JOB) "); - maybe_more = FALSE; - } - else { - printf("JUST A SIMPLE 'YES' OR 'NO' PLEASE, %s. ", name); - } - } // no further questions - } // end of 'not done' loop - printf("\nTHAT WILL BE $5.00 FOR THE ADVICE, %s.\n", name); - printf("PLEASE LEAVE THE MONEY ON THE TERMINAL.\n"); - // pause a few seconds - printf("\n\n\nDID YOU LEAVE THE MONEY "); - get_input(reply); - while (!paid) { - if (strings_match(reply, "YES")) { - printf("HEY, %s??? YOU LEFT NO MONEY AT ALL!\n", name); - printf("YOU ARE CHEATING ME OUT OF MY HARD-EARNED LIVING.\n"); - printf("\nWHAT A RIP OFF, %s!!!\n", name); - printf("TAKE A WALK, %s.\n\n", name); - paid = TRUE; - } - else if (strings_match(reply, "NO")) { - printf("THAT'S HONEST, %s, BUT HOW DO YOU EXPECT " - "ME TO GO ON WITH MY PSYCHOLOGY STUDIES IF MY PATIENTS " - "DON'T PAY THEIR BILLS?\n\n", name); - printf("NICE MEETING YOU, %s, HAVE A NICE DAY.\n", name); + } // no further questions + } // end of 'not done' loop + + printf("\nTHAT WILL BE $5.00 FOR THE ADVICE, %s.\n", name); + printf("PLEASE LEAVE THE MONEY ON THE TERMINAL.\n"); + // pause a few seconds + printf("\n\n\nDID YOU LEAVE THE MONEY "); + get_input(reply); + while (!paid) { + if (strings_match(reply, "YES")) { + printf("HEY, %s??? YOU LEFT NO MONEY AT ALL!\n", name); + printf("YOU ARE CHEATING ME OUT OF MY HARD-EARNED LIVING.\n"); + printf("\nWHAT A RIP OFF, %s!!!\n", name); + printf("TAKE A WALK, %s.\n\n", name); paid = TRUE; - } - else { - printf("YOUR ANSWER OF '%s' CONFUSES ME, %s.\n", reply, name); - printf("PLEASE RESPOND WITH 'YES' OR 'NO'.\n"); - } - } + } + else if (strings_match(reply, "NO")) { + printf("THAT'S HONEST, %s, BUT HOW DO YOU EXPECT " + "ME TO GO ON WITH MY PSYCHOLOGY STUDIES IF MY PATIENTS " + "DON'T PAY THEIR BILLS?\n\n", name); + printf("NICE MEETING YOU, %s, HAVE A NICE DAY.\n", name); + paid = TRUE; + } + else { + printf("YOUR ANSWER OF '%s' CONFUSES ME, %s.\n", reply, name); + printf("PLEASE RESPOND WITH 'YES' OR 'NO'.\n"); + } + } } + + void tab(int number_of_spaces) { - for (int i=0; i < number_of_spaces; i++) - putchar(' '); + for (int i=0; i < number_of_spaces; i++) + putchar(' '); } + + void get_input(char *input_buffer) { - fgets(input_buffer, MAX_INPUT_LENGTH - 1, stdin); - input_buffer[strcspn(input_buffer, "\n")] = '\0'; // trim the trailing line break + fgets(input_buffer, MAX_INPUT_LENGTH - 1, stdin); + input_buffer[strcspn(input_buffer, "\n")] = '\0'; // trim the trailing line break } + + int strings_match(char *string1, char *string2) { - if (strncasecmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0) - return FALSE; - else // strings match, at least within maximum input line length - return TRUE; + if (strncasecmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0) + return FALSE; + else // strings match, at least within maximum input line length + return TRUE; } + From 00d7a10bee6cceb24454a794323cd66a4d5f9b3b Mon Sep 17 00:00:00 2001 From: nrezmerski <108252649+nrezmerski@users.noreply.github.com> Date: Fri, 18 Jul 2025 06:06:12 -0500 Subject: [PATCH 4/4] Create hello.swift --- .../45_Hello/Swift/hello.swift | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 00_Alternate_Languages/45_Hello/Swift/hello.swift diff --git a/00_Alternate_Languages/45_Hello/Swift/hello.swift b/00_Alternate_Languages/45_Hello/Swift/hello.swift new file mode 100644 index 000000000..0d882f755 --- /dev/null +++ b/00_Alternate_Languages/45_Hello/Swift/hello.swift @@ -0,0 +1,157 @@ + +func tab(_ number_Of_Spaces: Int) { + var spaces = "" + + for _ in 1...number_Of_Spaces { + spaces += " " + } + print(spaces, terminator:"") +} + + +func get_Input() -> String { + let input = readLine() + return (input == nil ? "" : input!.uppercased()) +} + + +func main() +{ + var done = false, + answered = false, + maybe_More = false, + paid = false + var reply = "" + var name = "STRANGER" + + tab (33) + print("HELLO") + tab (15) + print("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n") + + print("HELLO. MY NAME IS CREATIVE COMPUTER.") + print("WHAT'S YOUR NAME? ") + let input = readLine() + if (input != nil && input != "") { + name = input!.uppercased() + } + + print("\nHI THERE, \(name), ARE YOU ENJOYING YOURSELF HERE?") + + reply = get_Input() + while (reply != "YES" && reply != "NO") { + print("\(name), I DON'T UNDERSTAND YOUR ANSWER OF '\(reply)'.") + print("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE?") + reply = get_Input() + } + + if (reply == "YES") { + print("\nI'M GLAD TO HEAR THAT, \(name).\n") + } + else { + print("\nOH, I'M SORRY TO HEAR THAT, \(name). MAYBE WE CAN " + + "BRIGHTEN UP YOUR VISIT A BIT.\n") + } + + print("SAY, \(name), I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT " + + "THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO " + + "YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB)?") + + while (!done) { + reply = get_Input() + + if (reply == "JOB") { + print("\nI CAN SYMPATHIZE WITH YOU \(name). I HAVE TO WORK " + + "VERY LONG HOURS FOR NO PAY -- AND SOME OF MY BOSSES " + + "REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, \(name), IS TO " + + "OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n") + } + + else if (reply == "MONEY") { + print("\nSORRY, \(name), I'M BROKE TOO. WHY DON'T YOU SELL " + + "ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING " + + "SO YOU WON'T NEED SO MUCH MONEY?\n") + } + + else if (reply == "HEALTH") { + print("\nMY ADVICE TO YOU \(name) IS:") + print(" 1. TAKE TWO ASPRIN") + print(" 2. DRINK PLENTY OF FLUIDS (ORANGE JUICE, NOT BEER!)") + print(" 3. GO TO BED (ALONE)\n") + } + + else if (reply == "SEX") { + print("\nIS YOUR PROBLEM TOO MUCH OR TOO LITTLE?") + + answered = false + while (!answered) { + reply = get_Input() + if (reply == "TOO MUCH") { + print("\nYOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!") + print("IF IT BOTHERS YOU, \(name), TAKE A COLD SHOWER.\n") + answered = true + } + else if (reply == "TOO LITTLE") { + print("\nWHY ARE YOU HERE IN SUFFERN, \(name)? YOU SHOULD BE " + + "IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME " + + "REAL ACTION.\n") + answered = true + } + else { + print("\nDON'T GET ALL SHOOK, \(name), JUST ANSWER THE QUESTION " + + "WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT?") + } + } + } + + else { // not one of the prescribed categories + print("\nOH, \(name), YOUR ANSWER OF '\(reply)' IS GREEK TO ME.\n") + } + + print("\nANY MORE PROBLEMS YOU WANT SOLVED, \(name)? ") + + maybe_More = true + while (maybe_More) { + reply = get_Input() + if (reply == "NO") { + done = true + maybe_More = false + } + else if (reply == "YES") { + print("\nWHAT KIND (SEX, MONEY, HEALTH, JOB) ") + maybe_More = false + } + else { + print("\nJUST A SIMPLE 'YES' OR 'NO' PLEASE, \(name). ") + } + } // no further questions + } // end of 'not done' loop + + print("\nTHAT WILL BE $5.00 FOR THE ADVICE, \(name).") + print("PLEASE LEAVE THE MONEY ON THE TERMINAL.") + // pause a few seconds + print("\n\n\nDID YOU LEAVE THE MONEY? ") + reply = get_Input() + while (!paid) { + if (reply == "YES") { + print("\nHEY, \(name)??? YOU LEFT NO MONEY AT ALL!") + print("YOU ARE CHEATING ME OUT OF MY HARD-EARNED LIVING.\n") + print("WHAT A RIP OFF, \(name)!!!\n") + print("TAKE A WALK, \(name).") + paid = true + } + else if (reply == "NO") { + print("THAT'S HONEST, \(name), BUT HOW DO YOU EXPECT " + + "ME TO GO ON WITH MY PSYCHOLOGY STUDIES IF MY PATIENTS " + + "DON'T PAY THEIR BILLS?\n") + print("NICE MEETING YOU, \(name), HAVE A NICE DAY.") + paid = true + } + else { + print("YOUR ANSWER OF '\(reply)' CONFUSES ME, \(name).") + print("PLEASE RESPOND WITH 'YES' OR 'NO'.") + } + } +} + +main()