Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct Product
- {
- //Coca-Cola, Milka, etc..
- char name;
- //liquid, chocolate, cake, etc..
- char type;
- //weight of the product
- float weight;
- //product price
- float price;
- //amount of the product
- int amount;
- };
- //create 27 products with random parameters and return them as array
- struct Product* createProducts();
- //function to test if the array is filled succesfully
- void printStock(struct Product* array);
- int main()
- {
- //Vending machine size;
- int X,Y;
- //Array containing all the products
- struct Product *productsArray = createProducts();
- //print the array with all the products
- printStock(productsArray);
- //input X size
- scanf("%d", &X);
- //input Y size
- scanf("%d", &Y);
- //3-dimensional array containing the products in a sorted way.
- struct Product VendingMachine[X][Y][3];
- return 0;
- }
- struct Product* createProducts(){
- static struct Product products[27];
- for(int i = 0; i < 27; i++){
- struct Product product = {'A' + i, 'a' + i, 0.1 + i, 1.0 + i, 1 + i/2};
- products[i] = product;
- }
- return products;
- }
- void printStock(struct Product* array){
- for(int i = 0 ; i < 27; i++){
- printf("Product%d: name: %c, type: %c, weight: %.2f, price: %.2f, amount: %d \n",
- i + 1, (array + i)->name, (array + i)->type, (array + i)->weight,
- (array + i)->price, (array + i)->amount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement