In: Computer Science
C
Assign Barbecue's data member caloriesInSlice with a value read from input. Then, assign Ham and Cheese's data member caloriesInSlice with another value read from input. Input will contain two integer numbers.
#include <stdio.h>
#include <string.h>
typedef struct Pizza_struct {
char pizzaName[75];
int caloriesPerSlice;
} Pizza;
int main(void) {
Pizza pizzasList[2];
strcpy(pizzasList[0].pizzaName, "Barbecue");
strcpy(pizzasList[1].pizzaName, "Ham and Cheese");
/* Your code goes here */
printf("A %s slice contains %d calories.\n",
pizzasList[0].pizzaName, pizzasList[0].caloriesPerSlice);
printf("A %s slice contains %d calories.\n",
pizzasList[1].pizzaName, pizzasList[1].caloriesPerSlice);
return 0;
}
As per the given question, we are required to get two integers number which are pizzaList structure caloriesPerSlice values and assign appropriately.
Scan both the integers values and assign it to it's appropriate structure array values.
Scan the first integer value and store it in the pizzaList array of structure at it's caloriesPerSlice as shown below:
scanf("%d", &pizzaList[0].caloriesPerSlice);
Scan the second integer value and store it in the pizzaList array of structure at it's caloriesPerSlice as shown below:
scanf("%d", &pizzaList[1].caloriesPerSlice);
/* Final code*/
include <stdio.h>
#include <string.h>
typedef struct Pizza_struct {
char pizzaName[75];
int caloriesPerSlice;
} Pizza;
int main(void) {
Pizza pizzasList[2];
strcpy(pizzasList[0].pizzaName, "Barbecue");
strcpy(pizzasList[1].pizzaName, "Ham and Cheese");
scanf("%d", &pizzaList[0].caloriesPerSlice);
scanf("%d", &pizzaList[1].caloriesPerSlice);
printf("A %s slice contains %d calories.\n", pizzasList[0].pizzaName, pizzasList[0].caloriesPerSlice);
printf("A %s slice contains %d calories.\n", pizzasList[1].pizzaName, pizzasList[1].caloriesPerSlice);
return 0;
}