fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. char top[20];
  13. struct flavor
  14. {
  15. char name[20];
  16. double small_price;
  17. double medium_price;
  18. double large_price;
  19. struct flavor *next;
  20. struct flavor *prev;
  21. };
  22. typedef struct flavor f;
  23. f *head = NULL;
  24. f *tail = NULL;
  25.  
  26. void add_flavor(char name[], double small_price, double medium_price, double large_price)
  27. {
  28. f *new_flavor = (f*) malloc(sizeof(f));
  29. strcpy(new_flavor->name, name);
  30. new_flavor->small_price = small_price;
  31. new_flavor->medium_price = medium_price;
  32. new_flavor->large_price = large_price;
  33. new_flavor->next = NULL;
  34. new_flavor->prev = tail;
  35. if (tail != NULL)
  36. {
  37. tail->next = new_flavor;
  38. }
  39. tail = new_flavor;
  40. if (head == NULL)
  41. {
  42. head = new_flavor;
  43. }
  44. }
  45.  
  46.  
  47.  
  48. void display_flavors()
  49. {
  50. f *current = head;
  51. int i=1;
  52. while (current != NULL)
  53. {
  54. printf("\n%d\n",i);
  55. printf("%s:\n", current->name);
  56. printf("Small - %.2f INR\n", current->small_price);
  57. printf("Medium - %.2f INR\n", current->medium_price);
  58. printf("Large - %.2f INR\n", current->large_price);
  59. i=i+1;
  60. current = current->next;
  61.  
  62. }
  63. }
  64.  
  65. void purchase_flavor(char name[], char size[])
  66. {
  67. f *current = head;
  68. while (current != NULL)
  69. {
  70. if (strcasecmp(current->name, name) == 0)
  71. {
  72. double price;
  73. if (strcasecmp(size, "Small") == 0)
  74. {
  75. price = current->small_price;
  76. }
  77. else if (strcasecmp(size, "Medium") == 0)
  78. {
  79. price = current->medium_price;
  80. }
  81. else if (strcasecmp(size, "Large") == 0)
  82. {
  83. price = current->large_price;
  84. }
  85. else
  86. {
  87. printf("Invalid size.\n");
  88. return;
  89. }
  90. printf("You have purchased a %s Ice cream of Size %s,for %.2f INR.\n", current->name, size,top, price);
  91. return;
  92. }
  93. current = current->next;
  94. }
  95. printf("Sorry, we don't have %s flavor.\n", name);
  96. }
  97.  
  98.  
  99. int main()
  100. {
  101. add_flavor("Vanilla", 20.0, 30.0, 40.0);
  102. add_flavor("Chocolate", 25.0, 35.0, 45.0);
  103. add_flavor("Strawberry", 30.0, 40.0, 50.0);
  104. add_flavor("Mango", 35.0, 45.0, 55.0);
  105. add_flavor("Butterscotch", 40.0, 50.0, 60.0);
  106. add_flavor("Pista", 40.0, 50.0, 60.0);
  107. add_flavor("Chocochip", 40.0, 50.0, 60.0);
  108. add_flavor("Malai", 40.0, 50.0, 60.0);
  109. add_flavor("Pineapple", 40.0, 50.0, 60.0);
  110. add_flavor("Guava", 40.0, 50.0, 60.0);
  111. printf("Welcome to the ice cream vending machine!\n");
  112. printf("Please select a flavor and size:\n");
  113. display_flavors();
  114. char selected_flavor[20];
  115. char selected_size[10];
  116. scanf("%s %s", selected_flavor, selected_size);
  117. purchase_flavor(selected_flavor, selected_size);
  118. int z;
  119. printf("Press 1 if u want any extra topping");
  120. scanf("%d",&z);
  121. switch(z)
  122. {
  123. case 1:printf("\nEnter your choice of toppings for the icecream:\nCherries\nNuts\nSprinklers\nPrettzels\nMarshmellow");
  124. scanf("%s",top);
  125. printf("\nTopping choosen=%s",top);
  126. break;
  127. default:exit(0);
  128. }
  129. return 0;
  130. }
Success #stdin #stdout 0.01s 5444KB
stdin
vanilla small
1
cherries
stdout
Welcome to the ice cream vending machine!
Please select a flavor and size:

1
Vanilla:
Small - 20.00 INR
Medium - 30.00 INR
Large - 40.00 INR

2
Chocolate:
Small - 25.00 INR
Medium - 35.00 INR
Large - 45.00 INR

3
Strawberry:
Small - 30.00 INR
Medium - 40.00 INR
Large - 50.00 INR

4
Mango:
Small - 35.00 INR
Medium - 45.00 INR
Large - 55.00 INR

5
Butterscotch:
Small - 40.00 INR
Medium - 50.00 INR
Large - 60.00 INR

6
Pista:
Small - 40.00 INR
Medium - 50.00 INR
Large - 60.00 INR

7
Chocochip:
Small - 40.00 INR
Medium - 50.00 INR
Large - 60.00 INR

8
Malai:
Small - 40.00 INR
Medium - 50.00 INR
Large - 60.00 INR

9
Pineapple:
Small - 40.00 INR
Medium - 50.00 INR
Large - 60.00 INR

10
Guava:
Small - 40.00 INR
Medium - 50.00 INR
Large - 60.00 INR
You have purchased a Vanilla Ice cream of Size small,for 20.00 INR.
Press 1 if u want any extra topping
Enter your choice of toppings for the icecream:
Cherries
Nuts
Sprinklers
Prettzels
Marshmellow
Topping choosen=cherries