Question: (MY CODE) Main.c #include #include ItemToPurchase.h #include ShoppingCart.h void PrintMenu(ShoppingCart usrShopping) { char myChar = ' '; char c = ' '; while (myChar !=

(MY CODE)

Main.c

#include #include "ItemToPurchase.h" #include "ShoppingCart.h"

void PrintMenu(ShoppingCart usrShopping) {

char myChar = ' ';

char c = ' ';

while (myChar != 'q') {

printf("MENU "); printf("a - Add item to cart "); printf("r - Remove item from cart "); printf("c - Change item quantity "); printf("i - Output items' descriptions "); printf("o - Output shopping cart "); printf("q - Quit ");

while (myChar != 'a' && myChar != 'r' && myChar != 'c' && myChar != 'i' && myChar != 'o' && myChar != 'q') {

printf("Choose an option: "); scanf(" %c", &myChar); }

if (myChar == 'a') {

while ((c = getchar()) != EOF && c != ' ');

char name[50]; char descr[50];

ItemToPurchase item;

printf("ADD ITEM TO CART ");

printf("Enter the item name: ");

//fgets(item.itemName, 50, stdin); fgets(name, 50, stdin);

int i = 0; while (name[i] != ' ') { item.itemName[i] = name[i]; ++i; } item.itemName[i] = '\0';

printf("Enter the item description: "); //fgets(item.itemDescription, 50, stdin); fgets(descr, 50, stdin);

i = 0; while (descr[i] != ' ') { item.itemDescription[i] = descr[i]; ++i; } item.itemDescription[i] = '\0';

printf("Enter the item price: "); scanf("%d", &item.itemPrice); printf("Enter the item quantity: "); scanf("%d", &item.itemQuantity);

usrShopping = AddItem(item, usrShopping);

printf(" "); myChar = ' ';

} else if (myChar == 'r') {

while ((c = getchar()) != EOF && c != ' ');

char temp[50]; char tempStr[50];

printf("REMOVE ITEM FROM CART ");

printf("Enter name of item to remove: ");

fgets(temp, 50, stdin);

int i = 0; while (temp[i] != ' ') { tempStr[i] = temp[i]; ++i; } tempStr[i] = '\0';

usrShopping = RemoveItem(tempStr, usrShopping);

myChar = ' ';

} else if (myChar == 'c') {

while ((c = getchar()) != EOF && c != ' ');

char temp[50]; char tempStr[50];

printf("CHANGE ITEM QUANTITY ");

printf("Enter the item name:"); fgets(temp, 50, stdin);

int i = 0; while (temp[i] != ' ') { tempStr[i] = temp[i]; ++i; } tempStr[i] = '\0';

usrShopping = ModifyItem(tempStr, usrShopping);

myChar = ' ';

} else if (myChar == 'i') { printf("OUTPUT ITEMS' DESCRIPTIONS "); PrintDescriptions(usrShopping); myChar = ' ';

} else if (myChar == 'o') { printf("OUTPUT SHOPPING CART "); PrintTotal(usrShopping); myChar = ' ';

}

} }

int main() {

ShoppingCart usrShopping; usrShopping.cartSize = 0;

printf("Enter Customer's Name: "); gets(usrShopping.customerName); printf("Enter Today's Date: "); gets(usrShopping.currentDate);

printf("Customer Name: %s ", usrShopping.customerName); printf("Today's Date: %s ", usrShopping.currentDate);

PrintMenu(usrShopping);

return 0; }

ShoppingCart.C

#include "ShoppingCart.h" #include #include

ShoppingCart AddItem(ItemToPurchase item, ShoppingCart cart) { cart.cartItems[cart.cartSize] = item; cart.cartSize = cart.cartSize + 1; return cart; }

ShoppingCart RemoveItem(char name[], ShoppingCart cart) { int i = 0; char itemFound = 'n';

for (i = 0; i

if (strcmp(name, cart.cartItems[i].itemName) == 0) {

itemFound = 'y'; for (int j = i; j

if (itemFound == 'y') { cart.cartSize = cart.cartSize - 1; }

if (itemFound == 'n') { printf("Item not found in cart. Nothing removed. "); } return cart;

}

ShoppingCart ModifyItem(char item[50], ShoppingCart cart) { int quantity; char itemFound = 'n';

printf("Enter the new quantity:"); scanf("%d", &quantity);

int i = 0; for (i = 0; i

if (strcmp(item, cart.cartItems[i].itemName) == 0) {

itemFound = 'y'; cart.cartItems[i].itemQuantity = quantity; } } if (itemFound == 'n') { printf("Item not found in cart. Nothing modified."); } return cart;

}

int GetNumItemsInCart(ShoppingCart cart) { return cart.cartSize; }

int GetCostOfCart(ShoppingCart cart) { int total = 0; int temp = 0;

for (int i = 0; i

void PrintTotal(ShoppingCart cart) { int total = 0; int numOfItems = 0;

for (int i = 0; i

printf("%s\'s Shopping Cart - %s ", cart.customerName, cart.currentDate); printf("Number of Items: %d ", numOfItems);

if (cart.cartSize == 0) { printf("SHOPPING CART IS EMPTY "); printf("Total: $0 ");

} else { for (int i = 0; i

void PrintDescriptions(ShoppingCart cart) {

printf("%s's Shopping Cart - %s ", cart.customerName, cart.currentDate);

printf("Item Descriptions "); for (int i = 0; i

}

ShoppingCard.h

#ifndef SHOPPING_CART_H #define SHOPPING_CART_H

#include "ItemToPurchase.h" typedef struct ShoppingCart_struct { char customerName [50]; char currentDate [50]; ItemToPurchase cartItems [10]; int cartSize; } ShoppingCart;

ShoppingCart AddItem(ItemToPurchase item, ShoppingCart cart); ShoppingCart RemoveItem(char name[], ShoppingCart cart);

ShoppingCart ModifyItem(char item[50], ShoppingCart cart);

int GetNumItemsInCart(ShoppingCart cart);

int GetCostOfCart(ShoppingCart cart);

void PrintTotal(ShoppingCart cart);

void PrintDescriptions(ShoppingCart cart);

#endif

ItemToPurchase.c

#include "ItemToPurchase.h" #include #include

void MakeItemBlank(ItemToPurchase* item){ strcpy((*item).itemName, "none"); strcpy((*item).itemDescription, "none"); (*item).itemPrice=0; (*item).itemQuantity=0; }

// 1.2 void PrintItemCost(ItemToPurchase item){ printf("%s %d @ $%d = $%d ", item.itemName, item.itemQuantity, item.itemPrice, (item.itemPrice*item.itemQuantity)); }

void PrintItemDescription(ItemToPurchase item){ printf("%s: %s. ", item.itemName, item.itemDescription); }

ItemToPurchase.h

#ifndef ITEM_TO_PURCHASE_H #define ITEM_TO_PURCHASE_H

typedef struct ItemToPurchase_struct { char itemName[50]; char itemDescription[50]; int itemPrice; int itemQuantity; } ItemToPurchase;

void MakeItemBlank(ItemToPurchase* item);

void PrintItemCost(ItemToPurchase item);

void PrintItemDescription(ItemToPurchase item);

#endif

(can someone fix my code please??? I need it by midnight, Let me send the errors I receive)

(MY CODE) Main.c #include #include "ItemToPurchase.h" #include "ShoppingCart.h" void PrintMenu(ShoppingCart usrShopping) {char myChar = ' '; char c = ' '; while (myCharI needed By 11 PLEASE HELP ME I NEED HELP

7: Compare output A U73 Output is nearly correct; but whitespace differs. See highlights below. Special character legend John Doe February 1, 2016 f Input S a Enter customer's Name : Enter Today's Date: Customer Name: John Doe Today's Date: February 1, 2016 MENU a - Add item to cart r - Remove item from cart - Change item quantity i Output items' descriptions 0 - Output shopping cart q - Quit Your output Choose an option: Choose an option: Choose an option: Enter customer's Name: Enter Today's Date: Customer Name: John Doe Today's Date: February 1, 2016 Expected output MENU a - Add item to cart r - Remove item from cart c - change item quantity i - Output items' descriptions 0 - Output shopping cart q - Quit Choose an option: Choose an option: Choose an option: 8: Compare output 073 Output differs. See highlights below. Special character legend John Doe February 1, 2016 Input O a OUTPUT SHOPPING CART John Doe's Shopping Cart Number of Items: 0 February 1, 2016 Your output ends with SHOPPING CART IS EMPTY Total: $0 MENU a Add item to cart r - Remove item from cart C - Change item quantity i Output items' descriptions 0 - Output shopping cart q Quit Choose an option: OUTPUT SHOPPING CART John Doe's Shopping Cart Number of Items: 0 February 1, 2016 SHOPPING CART IS EMPTY Total: $0 Expected output ends with r MENU Add item to cart Remove item from cart Change item quantity i - Output items' descriptions O - Output shopping cart q - Quit Choose an option

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!