In mainc Build the Item ToPurchase struct with the following

In main.c Build the Item ToPurchase struct with the following specifications: Data members char itemName [ o int itemPrice o c o int itemQuantity and create two functions MakeltemBlank0 Has a pointer to an ItemToPurchase parameter. Reference Figure 7.4.1. Sets item\'s name = \"none\", item\'s price = 0, item\'s quantity = 0-PrintItemCost0-Has an Item ToPurchase parameter. Ex. of PrintltemCost0 output: Bottled water 10 @ $1 $10 (2) In main0, prompt the user for two tems and create two objects of the Item ToPurchase struct. Before prompting for the second item, enter flush(stdin); to allow the user to input a new string

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);
}

 In main.c Build the Item ToPurchase struct with the following specifications: Data members char itemName [ o int itemPrice o c o int itemQuantity and create tw

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site