Advertisement
imthaking

go

Nov 28th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. typedef enum { FALSE, TRUE } Boolean;
  5. Boolean namecheck();
  6. Boolean lastnamecheck();
  7. Boolean idcheck();
  8. void firstoption();
  9. Boolean agecheck();
  10. Boolean Isbigletter(char c);
  11. Boolean Issmallletter(char c);
  12. Boolean Isnumber(char c);
  13. Boolean emailcheck();
  14. Boolean digitcardcheck();
  15. int firstscreen();
  16.  
  17. int main()
  18. {
  19. int temp = 0;
  20. namecheck();
  21. idcheck();
  22. temp = firstscreen();
  23. if (temp == 4)
  24. return 0;
  25. else
  26. if (temp == 1)
  27. {
  28. firstoption();
  29. }
  30.  
  31.  
  32.  
  33. getchar();
  34.  
  35. }
  36.  
  37. Boolean namecheck()
  38. {
  39. Boolean bool = FALSE;
  40. char name = 0;
  41. while (bool == FALSE)
  42. {
  43. fflush(stdin);
  44. printf("Please enter your name\n");
  45. name = getchar();
  46. if (Isbigletter(name))
  47. {
  48. fflush(stdin);
  49. name = getchar();
  50. while (Issmallletter(name))
  51. {
  52. fflush(stdin);
  53. name = getchar();
  54. }
  55. if (name == '.')
  56. {
  57. return TRUE;
  58. }
  59. else
  60. {
  61. printf("Invalid character\n");
  62. }
  63. }
  64. else
  65. {
  66. printf("Invalid character\n");
  67. }
  68. }
  69. }
  70. Boolean lastnamecheck()
  71. {
  72. Boolean bool = FALSE;
  73. char name = 0;
  74. while (bool == FALSE)
  75. {
  76. fflush(stdin);
  77. printf("Please enter your last name\n");
  78. name = getchar();
  79. if (Isbigletter(name))
  80. {
  81. fflush(stdin);
  82. name = getchar();
  83. while (Issmallletter(name))
  84. {
  85. fflush(stdin);
  86. name = getchar();
  87. }
  88. if (name == '.')
  89. {
  90. return TRUE;
  91. }
  92. else
  93. {
  94. printf("Invalid character\n");
  95. }
  96. }
  97. else
  98. {
  99. printf("Invalid character\n");
  100. }
  101. }
  102. }
  103. Boolean Isbigletter(char c)
  104. {
  105. if ((c > 64) && (c < 91))
  106. return TRUE;
  107. return FALSE;
  108. }
  109. Boolean Issmallletter(char c)
  110. {
  111. if ((c > 96) && (c < 123))
  112. return TRUE;
  113. return FALSE;
  114. }
  115. Boolean Isnumber(char c)
  116. {
  117. if ((c > 47) && (c < 58))
  118. return TRUE;
  119. return FALSE;
  120. }
  121. Boolean idcheck()
  122. {
  123. Boolean bool = FALSE;
  124. char id = 0;
  125. int counter = 0;
  126. while (bool == FALSE)
  127. {
  128. fflush(stdin);
  129. printf("Please enter your ID number\n");
  130. id = getchar();
  131. counter++;
  132. if (Isnumber(id))
  133. {
  134. fflush(stdin);
  135. id = getchar();
  136. counter++;
  137. while (Isnumber(id))
  138. {
  139. fflush(stdin);
  140. id = getchar();
  141. counter++;
  142. if (counter == 9)
  143. {
  144. return TRUE;
  145. }
  146. }
  147.  
  148.  
  149. printf("Invalid character\n");
  150. counter = 0;
  151. }
  152. else
  153. {
  154. printf("Invalid character\n");
  155. counter = 0;
  156. }
  157. }
  158. }
  159. int firstscreen()
  160. {
  161. int option = 0;
  162. int illcount = 1;
  163. printf("Thank you for choosing SCE Internet Company! How can we help you?\n");
  164. printf("1) I want to join your company as a new client.\n");
  165. printf("2) I want to find out some details about my already existing account.\n");
  166. printf("3) I want to leave your company.\n");
  167. printf("4) I want to exit the chat.\n");
  168. scanf_s("%d", &option);
  169. if ((option > 0) && (option < 5))
  170. return option;
  171. while (illcount != 0)
  172. {
  173. if (((option < 1) || (option > 4)))
  174. {
  175. if (illcount < 3)
  176. {
  177. illcount++;
  178. printf("An illegal option! This is the %d time you chose an illegal option\n", illcount - 1);
  179. printf("Please retry.\n");
  180. printf("Thank you for choosing SCE Internet Company! How can we help you?\n");
  181. printf("1) I want to join your company as a new client.\n");
  182. printf("2) I want to find out some details about my already existing account.\n");
  183. printf("3) I want to leave your company.\n");
  184. printf("4) I want to exit the chat.\n");
  185. scanf_s("%d", &option);
  186. }
  187. }
  188. if (illcount >= 3)
  189. {
  190. illcount++;
  191. printf("Please come back only when you need something. Have a good day!\n", illcount-1);
  192. getchar();
  193. getchar();
  194. return 4;
  195. }
  196. if ((option > 0) && (option < 5))
  197. {
  198. illcount = 0;
  199. return option;
  200. }
  201. }
  202. illcount = 0;
  203. return option;
  204. }
  205. Boolean agecheck()
  206. {
  207. Boolean bool = FALSE;
  208. short age = 0;
  209. while (bool == FALSE)
  210. {
  211. fflush(stdin);
  212. printf("Please enter your age\n");
  213. scanf_s("%hd" ,&age);
  214. if ((age > 17) && (age < 121))
  215. {
  216. return TRUE;
  217. }
  218. else
  219. printf("Invalid age\n");
  220. }
  221. }
  222. Boolean emailcheck()
  223. {
  224. Boolean bool = FALSE;
  225. char mail = 0;
  226. char mailtemp = 0;
  227. while (bool == FALSE)
  228. {
  229. fflush(stdin);
  230. printf("Please enter your Email address\n");
  231. mail = getchar();
  232. if ((mail == '_') || (mail == '.') || (Isnumber(mail)) || (Isbigletter(mail)) || (Issmallletter(mail)))
  233. {
  234. fflush(stdin);
  235. mail = getchar();
  236. while ((mail == '_') || (mail == '.') || (Isnumber(mail)) || (Isbigletter(mail)) || (Issmallletter(mail)))
  237. {
  238. fflush(stdin);
  239. mail = getchar();
  240. }
  241. if (mail == '@')
  242. {
  243. fflush(stdin);
  244. mailtemp = getchar();
  245. while ((mailtemp == '.') || (Isnumber(mailtemp)) || (Issmallletter(mailtemp)) || (Isbigletter(mailtemp)))
  246. {
  247. fflush(stdin);
  248. mailtemp = getchar();
  249. }
  250. if (mailtemp == ' ')
  251. {
  252. return TRUE;
  253. }
  254. else
  255. printf("Invalid character\n");
  256. }
  257. else
  258. {
  259. printf("Invalid character\n");
  260. }
  261. }
  262. else
  263. {
  264. printf("Invalid character\n");
  265. }
  266. }
  267. }
  268. Boolean digitcardcheck()
  269. {
  270. Boolean bool = FALSE;
  271. int digit = 0;
  272. int temp = 1;
  273. printf("Enter your 4 last credit card digits\n");
  274. temp = scanf_s("%d", &digit);
  275. if (temp != 1)
  276. printf("Invalid character\n");
  277. while ((digit < 1000) || (digit > 9999))
  278. {
  279. printf("Error! Please enter only the 4 last digits\n");
  280. temp = scanf_s("%d", &digit);
  281. }
  282. return TRUE;
  283.  
  284. }
  285. void firstoption()
  286. {
  287. lastnamecheck();
  288. agecheck();
  289. emailcheck();
  290. digitcardcheck();
  291. printf("Thank you for choosing our company and welcome! Our people will contact you shortly!\n");
  292. firstscreen();
  293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement