Struct Softdrink

PHOTO EMBED

Sun Jun 09 2024 11:26:45 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c

#include <stdio.h>

struct Softdrink
{
	char name [16];
	int size;
	int energy;
	float caffeine;
	int max_daily;
};

void print_soft_drink(struct Softdrink a_soft_drink);

int main(void)
{
    struct Softdrink life_mod;

	sprintf(life_mod.name, "Life Modulus");
	life_mod.size = 250;
	life_mod.energy = 529;
	life_mod.caffeine = 80.5f;
	life_mod.max_daily = 500;

	print_soft_drink(life_mod);
	
	return 0;
}

void print_soft_drink(struct Softdrink a_soft_drink)
{
    
	printf("A soft drink...\n\n");
	printf("Name: %s\n",a_soft_drink.name);
	printf("Serving size: %d mL\n",a_soft_drink.size);
	printf("Energy content: %d kJ\n",a_soft_drink.energy);
	printf("Caffeine content: %f mg\n",a_soft_drink.caffeine);
	printf("Maximum daily intake: %d mL\n",a_soft_drink.max_daily);
}
content_copyCOPY

Requirements Declare Soft Drink Structure: Create a structure named SoftDrink that has the following members: Name (a character array with a maximum of 16 characters) Serving size (an integer representing millilitres) Energy content (an integer representing kilojoules) Caffeine content (a floating-point number representing milligrams) Maximum daily intake (an integer representing millilitres) Declare Structure Variable: Declare a variable of type SoftDrink named life_mod and set its members according to the given data: Name: "Life Modulus" Serving size: 250 mL Energy content: 529 kJ Caffeine content: 80.5 mg Maximum daily intake: 500 mL Create Print Function: Create a function named print_soft_drink that takes a SoftDrink parameter by value and prints its details in the format specified. For example: Result A soft drink... Name: Life Modulus Serving size: 250 mL Energy content: 529 kJ Caffeine content: 80.500000 mg Maximum daily intake: 500 mL