Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct Product
  6. {
  7.     //Coca-Cola, Milka, etc..
  8.     char name;
  9.    
  10.     //liquid, chocolate, cake, etc..
  11.     char type;
  12.    
  13.     //weight of the product
  14.     float weight;
  15.    
  16.     //product price
  17.     float price;
  18.    
  19.     //amount of the product
  20.     int amount;
  21. };
  22.  
  23. //create 27 products with random parameters and return them as array
  24. struct Product* createProducts();
  25.  
  26. //function to test if the array is filled succesfully
  27. void printStock(struct Product* array);
  28.  
  29. int main()
  30. {
  31.     //Vending machine size;
  32.     int X,Y;
  33.    
  34.     //Array containing all the products
  35.     struct Product *productsArray = createProducts();
  36.    
  37.     //print the array with all the products
  38.     printStock(productsArray);
  39.    
  40.     //input X size
  41.     scanf("%d", &X);
  42.    
  43.     //input Y size
  44.     scanf("%d", &Y);
  45.    
  46.     //3-dimensional array containing the products in a sorted way.
  47.     struct Product VendingMachine[X][Y][3];
  48.  
  49.     return 0;
  50. }
  51.  
  52. struct Product* createProducts(){
  53.         static struct Product products[27];
  54.        
  55.         for(int i = 0; i < 27; i++){
  56.             struct Product product = {'A' + i, 'a' + i, 0.1 + i, 1.0 + i, 1 + i/2};
  57.             products[i] = product;
  58.         }
  59.     return products;
  60. }
  61.  
  62. void printStock(struct Product* array){
  63.     for(int i = 0 ; i < 27; i++){
  64.         printf("Product%d: name: %c, type: %c, weight: %.2f, price: %.2f, amount: %d \n",
  65.             i + 1, (array + i)->name, (array + i)->type, (array + i)->weight,
  66.             (array + i)->price, (array + i)->amount);
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement