In mainc Build the Item ToPurchase struct with the following
Solution
Here is the code for you:
#include <stdio.h>
#include <string.h>
typedef struct ItemToPurchase
{
char itemName[80];
int itemPrice;
int itemQuantity;
}ItemToPurchase;
void MakeItemBlank(ItemToPurchase *item)
{
strcpy(item->itemName, \"none\");
item->itemPrice = 0;
item->itemQuantity = 0;
}
void PrintItemCost(ItemToPurchase item)
{
printf(\"%s %d @ $%d = $%d\ \", item.itemName, item.itemQuantity, item.itemPrice, item.itemQuantity * item.itemPrice);
}
int main()
{
ItemToPurchase item[2];
int totalCost = 0, temp;
for(int i = 0; i < 2; i++)
{
printf(\"Item %d\ \", i+1);
fflush(stdin);
printf(\"Enter the item name:\ \");
gets(item[i].itemName);
printf(\"Enter the item price: \");
scanf(\"%d\", &temp);
item[i].itemPrice = temp;
printf(\"Enter the item quantity: \");
scanf(\"%d\", &temp);
item[i].itemQuantity = temp;
totalCost += item[i].itemQuantity * item[i].itemPrice;
}
printf(\"TOTAL COST\ \");
PrintItemCost(item[0]);
PrintItemCost(item[1]);
printf(\"\ Total: $%d\ \", totalCost);
}
