Advertisement
Guest User

Untitled

a guest
Feb 26th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. //char password[15] = "L3tM3in";
  7. //char username[15] = "Admin19";
  8. int a = 40; //Amoxil
  9. int s = 40; //Synthroid
  10. int z = 30;//Zestril
  11. int v = 10;//Vicodin
  12.  
  13.  
  14. void login();
  15. void menu(int *option);
  16. void refill(int *a, int *quantity);
  17. void dispense(int *drug, int *amount);
  18. //void dispenseS(int *s, int *quantity);
  19. //void dispenseZ(int *z, int *quantity);
  20. //void dispenseV(int *v, int *quantity);
  21.  
  22.  
  23. int main()
  24. {
  25. login();
  26.  
  27.  
  28.  
  29. int option = 0;
  30. while(option != 4){
  31. printf(" Drug Admin. System\n");
  32. printf("Menu:\n 1.Check Quantity\n 2.Refill\n 3.Dispense\n 4.Quit\n\nSelect Option:\n");
  33. scanf("%d", &option);
  34. menu(&option);
  35.  
  36. }
  37.  
  38.  
  39. return 0;
  40.  
  41.  
  42.  
  43. }
  44. void menu(int *option){
  45.  
  46. /*int a = 40; //Amoxil
  47. int s = 40; //Synthroid
  48. int z = 30;//Zestril
  49. int v = 10;//Vicodin*/
  50.  
  51. switch(*option){
  52. case 1:{
  53. system("@cls||clear");
  54. printf(" Current Quantities\n");
  55. printf("Amoxil %d\nSynthroid %d\nZestril %d\nVicodin %d\n\n", a, s, z, v);
  56. getchar();
  57. char pick;
  58. char next;
  59. int count = 0;
  60. while(pick != 'b' || count != 2){
  61. count = 0;
  62. next = 'c';
  63. printf("Return to menu press b: \n");
  64. while(next != '\n'){
  65. next = getchar();
  66. if(count == 0){
  67. pick = next;
  68.  
  69.  
  70. }
  71. count++;
  72.  
  73. }
  74.  
  75. }
  76. system("@cls||clear");
  77. break;
  78.  
  79. }
  80.  
  81.  
  82. case 2:{
  83. int choice = 0;
  84. int quantity = 0;
  85. system("@cls||clear");
  86. printf("Select drug by #\n1.Amoxil 2. Synthroid 3. Zestril 4. Vicodin\n");
  87. scanf("%d", &choice);
  88. printf("Enter refill quantity:");
  89. scanf("%d", &quantity);
  90. if(choice ==1)
  91. refill(&a, &quantity);
  92.  
  93.  
  94. else if(choice ==2)
  95. refill(&s, &quantity);
  96.  
  97. else if(choice == 3)
  98. refill(&z, &quantity);
  99. else if (choice == 4)
  100. refill(&v, &quantity);
  101. else{
  102.  
  103. }
  104.  
  105.  
  106. break;
  107.  
  108. }
  109.  
  110. case 3:{
  111. int choice = 0;
  112. int quantity = 0;
  113. system("@cls||clear");
  114. printf("Select drug by #\n1.Amoxil 2. Synthroid 3. Zestril 4. Vicodin\n");
  115. scanf("%d", &choice);
  116. printf("Enter quantity to dispense:");
  117. scanf("%d", &quantity);
  118. if(choice ==1)
  119. dispense(&a, &quantity);
  120. else if(choice ==2)
  121. dispense(&s, &quantity);
  122. else if(choice == 3)
  123. dispense(&z, &quantity);
  124. else if(choice == 4)
  125. dispense(&v, &quantity);
  126.  
  127. else{
  128.  
  129. }
  130.  
  131. break;
  132. }
  133. case 4:
  134. system("@cls||clear");
  135. printf("Quit program.");
  136.  
  137. }
  138.  
  139. system("@cls||clear");
  140. }
  141.  
  142. void refill(int *a, int *quantity){
  143. // printf("drug = %d\n",*a);
  144. // printf("quantity = %d",*quantity);
  145. *a+= *quantity;
  146. // printf("New drug amount is %d", *a);
  147. }
  148.  
  149. void dispense(int *drug, int *amount){
  150. if(*amount <= *drug){
  151. *drug-= *amount;
  152. }
  153. else if(*amount > *drug){
  154. printf("Not enough quantity to dispense.\n");
  155. getchar();
  156. char pick;
  157. char next;
  158. int count = 0;
  159. while((pick != 'n' && pick != 'y') || count != 2){
  160. count = 0;
  161. next = 'c';
  162. printf("Press y to go back to dispense again. Press n to return to main menu: \n");
  163. while(next != '\n'){
  164. next = getchar();
  165. if(count == 0){
  166. pick = next;
  167. //printf("%c", pick);
  168.  
  169. }
  170.  
  171. count++;
  172.  
  173. }
  174.  
  175. }
  176. if(pick == 'n'){
  177. //printf("heyo");
  178. return;
  179. }
  180.  
  181. else if(pick == 'y'){
  182. int temp = 3;
  183. menu(&temp);
  184. }
  185.  
  186. }
  187.  
  188. }
  189.  
  190.  
  191.  
  192. void login()
  193. {
  194. char username[15] = "Admin19";
  195. char password[15] = "L3tM3in";
  196. char username1;
  197. char password1;
  198.  
  199. int nameCorrect = 1;
  200. int passCorrect = 1;
  201. int i = 0;
  202. int j = 0;
  203.  
  204. int size = 7;
  205. do{
  206.  
  207. nameCorrect = 1;
  208. passCorrect = 1;
  209. i = 0;
  210. printf("Enter username:");
  211. username1 = getchar();
  212. while(username1 != '\n'){
  213. if(username[i] != username1){
  214. nameCorrect = 0;
  215. printf("no");
  216.  
  217. }
  218. i++;
  219. username1 = getchar();
  220.  
  221. }
  222. j = 0;
  223. printf("Enter Password:");
  224. password1 = getchar();
  225. while(password1 !='\n'){
  226. if(password[j] != password1){
  227. passCorrect = 0;
  228.  
  229. }
  230. j++;
  231. password1 = getchar();
  232.  
  233. }
  234.  
  235. system("@cls||clear");
  236.  
  237.  
  238. }while(((nameCorrect != 1) || (passCorrect != 1)) || i != size || j != size);
  239.  
  240.  
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement