fork(1) download
  1. #include <stdio.h>
  2.  
  3. /* Supporting structures */
  4. struct date { int month; int date; int year; };
  5.  
  6. struct producer {
  7. char name[100];
  8. char city[50];
  9. char state[50];
  10. char country[50];
  11. };
  12.  
  13. struct volume {
  14. float amount;
  15. char unit[10];
  16. };
  17.  
  18. struct priceInfo {
  19. float price;
  20. char currency[10];
  21. };
  22.  
  23. /* Base structures */
  24. struct Beer {
  25. int stockID;
  26. struct date bornOnDate;
  27. char type[70];
  28. char brand[100];
  29. float abv;
  30. struct producer brewery;
  31. struct volume container;
  32. struct priceInfo pricing;
  33. int ibu;
  34. int calories;
  35. int stockQuantity;
  36. int shelfLifeMonths;
  37. int isCraft;
  38. };
  39.  
  40. struct Wine {
  41. int stockID;
  42. char varietal[70];
  43. char brand[100];
  44. int vintage;
  45. float abv;
  46. char region[70];
  47. struct producer winery;
  48. struct volume container;
  49. struct priceInfo pricing;
  50. char sweetness[20];
  51. int agingMonths;
  52. int stockQuantity;
  53. int isSparkling;
  54. };
  55.  
  56. struct Spirits {
  57. int stockID;
  58. char type[50];
  59. char brand[100];
  60. int age;
  61. float abv;
  62. struct producer distillery;
  63. struct volume container;
  64. struct priceInfo pricing;
  65. char barrelType[50];
  66. int proof;
  67. int stockQuantity;
  68. int isImported;
  69. };
  70.  
  71. /* Test main function */
  72. int main(void) {
  73. /* Beer - Budweiser */
  74. struct Beer myBeer = {
  75. 1001, {8, 10, 2025}, "American Lager", "Budweiser", 5.0,
  76. {"Anheuser-Busch", "St. Louis", "Missouri", "USA"},
  77. {12.0, "oz"}, {1.99, "USD"}, 12, 145, 500, 6, 0
  78. };
  79.  
  80. /* Wine - Beringer */
  81. struct Wine myWine = {
  82. 2001, "Cabernet Sauvignon", "Beringer", 2020, 14.5,
  83. "Napa Valley",
  84. {"Beringer Vineyards", "St. Helena", "California", "USA"},
  85. {750.0, "ml"}, {24.99, "USD"}, "Dry", 18, 120, 0
  86. };
  87.  
  88. /* Spirits - Scotch */
  89. struct Spirits mySpirit = {
  90. 3001, "Scotch Whisky", "Johnnie Walker", 12, 40.0,
  91. {"Johnnie Walker Distillery", "Kilmarnock", "Ayrshire", "Scotland"},
  92. {750.0, "ml"}, {45.00, "USD"}, "Oak", 80, 80, 1
  93. };
  94.  
  95. /* Output */
  96. printf("Beer:\n Brand: %s\n Type: %s\n ABV: %.1f%%\n Price: %.2f %s\n\n",
  97. myBeer.brand, myBeer.type, myBeer.abv,
  98. myBeer.pricing.price, myBeer.pricing.currency);
  99.  
  100. printf("Wine:\n Brand: %s\n Varietal: %s\n ABV: %.1f%%\n Price: %.2f %s\n\n",
  101. myWine.brand, myWine.varietal, myWine.abv,
  102. myWine.pricing.price, myWine.pricing.currency);
  103.  
  104. printf("Spirit:\n Brand: %s\n Type: %s\n ABV: %.1f%%\n Price: %.2f %s\n",
  105. mySpirit.brand, mySpirit.type, mySpirit.abv,
  106. mySpirit.pricing.price, mySpirit.pricing.currency);
  107.  
  108. return 0;
  109. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Beer:
 Brand: Budweiser
 Type: American Lager
 ABV: 5.0%
 Price: 1.99 USD

Wine:
 Brand: Beringer
 Varietal: Cabernet Sauvignon
 ABV: 14.5%
 Price: 24.99 USD

Spirit:
 Brand: Johnnie Walker
 Type: Scotch Whisky
 ABV: 40.0%
 Price: 45.00 USD