1) Declare a struct named PatientData that contains two integer data members nam
ID: 643388 • Letter: 1
Question
1) Declare a struct named PatientData that contains two integer data members named heightInches and weightPounds. Sample output for the given program:
#include <stdio.h>
/* Your solution goes here */
int main(void) {
PatientData lunaLovegood;
lunaLovegood.heightInches = 63;
lunaLovegood.weightPounds = 115;
printf("Patient data: %d in, %d lbs ", lunaLovegood.heightInches, lunaLovegood.weightPounds);
return 0;
}
2) Write a statement to print the data members of InventoryTag. End with newline. Ex: if itemID is 314 and quantityRemaining is 500, print:
#include <stdio.h>
typedef struct InventoryTag_struct {
int itemID;
int quantityRemaining;
} InventoryTag;
int main(void) {
InventoryTag redSweater;
redSweater.itemID = 314;
redSweater.quantityRemaining = 500;
/* Your solution goes here */
return 0;
}
Explanation / Answer
Ans 1.
#include <stdio.h>
typedef struct InventoryTag_struct {
int heightInches;
int weightPounds;
}PatientData;
int main(void) {
PatientData lunaLovegood;
lunaLovegood.heightInches = 63;
lunaLovegood.weightPounds = 115;
printf("Patient data: %d in, %d lbs ", lunaLovegood.heightInches, lunaLovegood.weightPounds);
return 0;
}
Ans 2.
#include <stdio.h>
typedef struct InventoryTag_struct {
int itemID;
int quantityRemaining;
} InventoryTag;
int main(void) {
InventoryTag redSweater;
redSweater.itemID = 314;
redSweater.quantityRemaining = 500;
if(redSweater.itemID==314&&redSweater.quantityRemaining = 500)
{
printf("The itemID is : %d Quantity remaining is :%d",redSweater.itemID,redSweater.quantityRemaining);
}
return 0;
}
I am using the if statement when user will insert data itemID or remaining Quantitt if u want to do it then just type the follong statemnt to get your ans and dont initialize the value of itemID and remaining Quantity because it is meaning less it will increase the time complexity
printf("Enter itemID: ");
scanf("%d",&redSweater.itemID);
printf(" Enter Remaining Quantity :");
scanf("%d",&redSweater.quantityRemaining);
if u don't want this thing than remove if statement
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.