|
| 1 | +#include <stdio.h> |
| 2 | +#include <string.h> |
| 3 | + |
| 4 | +#define TRUE 1 |
| 5 | +#define FALSE 0 |
| 6 | +#define MAX_INPUT_LENGTH 80 |
| 7 | + |
| 8 | +void tab(int number_of_spaces); |
| 9 | +void get_input(char *input_buffer); |
| 10 | +int strings_match(char *string1, char *string2); |
| 11 | + |
| 12 | +int main() { |
| 13 | + int done = FALSE; |
| 14 | + int paid = FALSE; |
| 15 | + int maybe_more, sure; |
| 16 | + |
| 17 | + char name[MAX_INPUT_LENGTH]; |
| 18 | + char reply[MAX_INPUT_LENGTH]; |
| 19 | + |
| 20 | + tab(33); |
| 21 | + printf("HELLO\n"); |
| 22 | + tab(15); |
| 23 | + printf("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n"); |
| 24 | + printf("\n\n\n"); |
| 25 | + printf("HELLO. MY NAME IS CREATIVE COMPUTER.\n"); |
| 26 | + printf("\n\nWHAT'S YOUR NAME "); |
| 27 | + get_input(name); |
| 28 | + printf("\nHI THERE, %s, ARE YOU ENJOYING YOURSELF HERE ", name); |
| 29 | + |
| 30 | + get_input(reply); |
| 31 | + while (!strings_match(reply, "YES") && !strings_match(reply, "NO")) { |
| 32 | + printf("%s, I DON'T UNDERSTAND YOUR ANSWER OF '%s'.\n", name, reply); |
| 33 | + printf("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE "); |
| 34 | + get_input(reply); |
| 35 | + } |
| 36 | + |
| 37 | + if (strings_match(reply, "YES")) { |
| 38 | + printf("I'M GLAD TO HEAR THAT, %s.\n", name); |
| 39 | + } |
| 40 | + else { |
| 41 | + printf("OH, I'M SORRY TO HEAR THAT, %s. MAYBE WE CAN " |
| 42 | + "BRIGHTEN UP YOUR VISIT A BIT.\n", name); |
| 43 | + } |
| 44 | + |
| 45 | + printf("\nSAY, %s, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT " |
| 46 | + "THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO " |
| 47 | + "YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB) ", name); |
| 48 | + |
| 49 | + while (!done) { |
| 50 | + get_input(reply); |
| 51 | + |
| 52 | + if (strings_match(reply, "JOB")) { |
| 53 | + printf("I CAN SYMPATHIZE WITH YOU %s. I HAVE TO WORK " |
| 54 | + "VERY LONG HOURS FOR NO PAY -- AND SOME OF MY BOSSES " |
| 55 | + "REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, %s, IS TO " |
| 56 | + "OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n\n", name, name); |
| 57 | + } |
| 58 | + |
| 59 | + else if (strings_match(reply, "MONEY")) { |
| 60 | + printf("SORRY, %s, I'M BROKE TOO. WHY DON'T YOU SELL " |
| 61 | + "ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING " |
| 62 | + "SO YOU WON'T NEED SO MUCH MONEY?\n\n", name); |
| 63 | + } |
| 64 | + |
| 65 | + else if (strings_match(reply, "HEALTH")) { |
| 66 | + printf("MY ADVICE TO YOU %s IS:\n", name); |
| 67 | + printf(" 1. TAKE TWO ASPRIN\n"); |
| 68 | + printf(" 2. DRINK PLENTY OF FLUIDS (ORANGE JUICE, NOT BEER!)\n"); |
| 69 | + printf(" 3. GO TO BED (ALONE)\n\n"); |
| 70 | + } |
| 71 | + |
| 72 | + else if (strings_match(reply, "SEX")) { |
| 73 | + printf("IS YOUR PROBLEM TOO MUCH OR TOO LITTLE "); |
| 74 | + |
| 75 | + sure = FALSE; |
| 76 | + while (!sure) { |
| 77 | + get_input(reply); |
| 78 | + if (strings_match(reply, "TOO MUCH")) { |
| 79 | + printf("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!\n"); |
| 80 | + printf("IF IT BOTHERS YOU, %s, TAKE A COLD SHOWER.\n\n", name); |
| 81 | + sure = TRUE; |
| 82 | + } |
| 83 | + else if (strings_match(reply, "TOO LITTLE")) { |
| 84 | + printf("WHY ARE YOU HERE IN SUFFERN, %s? YOU SHOULD BE " |
| 85 | + "IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME " |
| 86 | + "REAL ACTION.\n\n", name); |
| 87 | + sure = TRUE; |
| 88 | + } |
| 89 | + else { |
| 90 | + printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION " |
| 91 | + "WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name); |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + else { // not one of the prescribed categories |
| 97 | + printf("OH, %s, YOUR ANSWER OF '%s' IS GREEK TO ME.\n\n", name, reply); |
| 98 | + } |
| 99 | + |
| 100 | + printf("ANY MORE PROBLEMS YOU WANT SOLVED, %s ", name); |
| 101 | + |
| 102 | + maybe_more = TRUE; |
| 103 | + while (maybe_more) { |
| 104 | + get_input(reply); |
| 105 | + if (strings_match(reply, "NO")) { |
| 106 | + done = TRUE; |
| 107 | + maybe_more = FALSE; |
| 108 | + } |
| 109 | + else if (strings_match(reply, "YES")) { |
| 110 | + printf("WHAT KIND (SEX, MONEY, HEALTH, JOB) "); |
| 111 | + maybe_more = FALSE; |
| 112 | + } |
| 113 | + else { |
| 114 | + printf("JUST A SIMPLE 'YES' OR 'NO' PLEASE, %s. ", name); |
| 115 | + } |
| 116 | + } // no further questions |
| 117 | + } // end of 'not done' loop |
| 118 | + |
| 119 | + printf("\nTHAT WILL BE $5.00 FOR THE ADVICE, %s.\n", name); |
| 120 | + printf("PLEASE LEAVE THE MONEY ON THE TERMINAL.\n"); |
| 121 | + // pause a few seconds |
| 122 | + printf("\n\n\nDID YOU LEAVE THE MONEY "); |
| 123 | + get_input(reply); |
| 124 | + while (!paid) { |
| 125 | + if (strings_match(reply, "YES")) { |
| 126 | + printf("HEY, %s??? YOU LEFT NO MONEY AT ALL!\n", name); |
| 127 | + printf("YOU ARE CHEATING ME OUT OF MY HARD-EARNED LIVING.\n"); |
| 128 | + printf("\nWHAT A RIP OFF, %s!!!\n", name); |
| 129 | + printf("TAKE A WALK, %s.\n\n", name); |
| 130 | + paid = TRUE; |
| 131 | + } |
| 132 | + else if (strings_match(reply, "NO")) { |
| 133 | + printf("THAT'S HONEST, %s, BUT HOW DO YOU EXPECT " |
| 134 | + "ME TO GO ON WITH MY PSYCHOLOGY STUDIES IF MY PATIENTS " |
| 135 | + "DON'T PAY THEIR BILLS?\n\n", name); |
| 136 | + printf("NICE MEETING YOU, %s, HAVE A NICE DAY.\n", name); |
| 137 | + paid = TRUE; |
| 138 | + } |
| 139 | + else { |
| 140 | + printf("YOUR ANSWER OF '%s' CONFUSES ME, %s.\n", reply, name); |
| 141 | + printf("PLEASE RESPOND WITH 'YES' OR 'NO'.\n"); |
| 142 | + } |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | + |
| 147 | +void tab(int number_of_spaces) { |
| 148 | + for (int i=0; i < number_of_spaces; i++) |
| 149 | + putchar(' '); |
| 150 | +} |
| 151 | + |
| 152 | + |
| 153 | +void get_input(char *input_buffer) { |
| 154 | + fgets(input_buffer, MAX_INPUT_LENGTH - 1, stdin); |
| 155 | + input_buffer[strcspn(input_buffer, "\n")] = '\0'; // trim the trailing line break |
| 156 | +} |
| 157 | + |
| 158 | + |
| 159 | +int strings_match(char *string1, char *string2) { |
| 160 | + if (strncasecmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0) |
| 161 | + return FALSE; |
| 162 | + else // strings match, at least within maximum input line length |
| 163 | + return TRUE; |
| 164 | +} |
| 165 | + |
| 166 | + |
0 commit comments