Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. char cake_name[255][255];
  6. int flour[255];
  7. int sugar[255];
  8. int butter[255];
  9. int egg[255];
  10. char cheese_type[255][255];
  11. int cheese[255];
  12. char softness[255][255];
  13. char sweet[255][255];
  14. char extra_cheese[255][255];
  15.  
  16. int total = 0;
  17.  
  18. void clear(){
  19. for( int i = 0 ; i < 30 ; ++i ){
  20. printf("\n");
  21. }
  22. }
  23.  
  24. void create_cake(){
  25. //name validation
  26. int flag;
  27. do{
  28. do{
  29. flag = 0;
  30. printf("Cake Name : ");
  31. scanf("%[^\n]", &cake_name[total]);fflush(stdin);
  32.  
  33. for( int i = 0 ; i < strlen(cake_name[total]) ; ++i ){
  34. if( isalpha(cake_name[total][i]) ){}
  35. else{
  36. flag = 1;
  37. }
  38. }
  39. }while( strlen(cake_name[total]) < 3 || strlen(cake_name[total]) > 10 );
  40. }while( flag == 1 );
  41.  
  42. //flour validation
  43. do{
  44. printf("flour : ");
  45. scanf("%d", &flour[total]);fflush(stdin);
  46. }while( flour[total] < 30 || flour[total] > 60 );
  47.  
  48. //sugar validation
  49. do{
  50. printf("sugar : ");
  51. scanf("%d", &sugar[total]);fflush(stdin);
  52. }while( sugar[total] < 30 || sugar[total] > 60 );
  53.  
  54. //butter validation
  55. do{
  56. printf("butter : ");
  57. scanf("%d", &butter[total]);fflush(stdin);
  58. }while( butter[total] < 20 || butter[total] > 60 );
  59.  
  60. //egg validation
  61. do{
  62. printf("egg : ");
  63. scanf("%d", &egg[total]);fflush(stdin);
  64. }while( egg[total] < 2 || egg[total] > 5 );
  65.  
  66. //cheese type validation
  67. do{
  68. printf("cheese type : ");
  69. scanf("%[^\n]", &cheese_type[total]);fflush(stdin);
  70. }while( strcmp(cheese_type[total], "Cream") != 0 && strcmp(cheese_type[total], "Cheddar") != 0 );
  71.  
  72. //cheese validation
  73. do{
  74. printf("cheese : ");
  75. scanf("%d", &cheese[total]);fflush(stdin);
  76. }while( cheese[total] < 100 || cheese[total] > 200 );
  77.  
  78. //softness validation
  79. if( flour[total] < 41 ){
  80. strcpy(softness[total], "Cotton");
  81. }else if( flour[total] >= 41 && flour[total] <= 50 ){
  82. strcpy(softness[total], "Soft");
  83. }else{
  84. strcpy(softness[total], "Normal");
  85. }
  86.  
  87. //sweet validation
  88. if( sugar[total] < 41 ){
  89. strcpy(sweet[total], "Normal");
  90. }else if( sugar[total] >= 41 && sugar[total] <= 50 ){
  91. strcpy(sweet[total], "Sweet");
  92. }else{
  93. strcpy(sweet[total], "Sugary");
  94. }
  95.  
  96. //extra cheese validation
  97. if( cheese[total] <= 150 ){
  98. strcpy(extra_cheese[total], "No");
  99. }else{
  100. strcpy(extra_cheese[total], "Yes");
  101. }
  102. printf("Success!");
  103. getchar(); //untuk tahan layar menu
  104. total++;
  105. }
  106.  
  107. void view_cake(){
  108. //no data validation
  109. if( total == 0 ){
  110. printf("No Data");
  111. }else{
  112. for( int i = 0 ; i < total ; ++i ){
  113. printf("%d %s %s %s %d %d %s %s\n",(i+1), cake_name[i], softness[i], sweet[i], butter[i], egg[i], extra_cheese[i], cheese_type[i]);
  114. }
  115. printf("Press Enter to continue");
  116. }
  117. getchar(); //untuk tahan layar menu
  118. }
  119.  
  120. int main(){
  121. int menu = 0;
  122. do{
  123. clear(); //untuk hapus layar
  124. printf("1. Create Cake\n");
  125. printf("2. View Cake\n");
  126. printf("3. Exit\n");
  127. printf("Choose : ");
  128. scanf("%d", &menu);fflush(stdin);
  129.  
  130. clear();
  131. if( menu == 1 ){
  132. create_cake();
  133. }
  134. else if( menu == 2 ){
  135. view_cake();
  136. }
  137. }while( menu != 3 );
  138. return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement