I am having trouble getting arrays to work how can i implement them into this, i jsut need arrays for the item and prices im struggled to get anything to work
Code:
#include <stdio.h>
struct store {
int Orange;
int Apple;
int Pear;
};
struct customer {
int budget;
};
void setupStore(struct store *store) {
printf("Please enter the price of Oranges :");
scanf(" %d", &store->Orange);
printf("Please enter the price of Apples :");
scanf(" %d", &store->Apple);
printf("Please enter the price of Pears :");
scanf(" %d", &store->Pear);
}
void setupCustomer(struct customer *customer) {
printf("**************************************\n");
printf("Hello and welcome to my fruit shop\n");
printf("Please enter your budget : ");
scanf(" %d", &customer->budget);
}
void Menu(const struct store *store) {
printf("**************************************\n");
printf("Shop Menu : \n");
printf("Item: Price:\n");
printf("O: %d\n", store->Orange);
printf("A: %d\n", store->Apple);
printf("P: %d\n", store->Pear);
}
char Choice(void) {
char ItemChosen;
printf("**************************************\n");
printf("Please type what item of fruit you would like to purchase : ");
scanf(" %c", &ItemChosen);
return ItemChosen;
}
void purchase(char itemCode, int itemCost, struct customer *customer) {
if (itemCost <= customer->budget) {
printf("Your purchase has been successful!\n");
printf("Purchase details\n");
printf("---------------------------------\n");
printf("Item selected : %c\n", itemCode);
printf("item price : %d\n", itemCost);
customer->budget -= itemCost;
printf("Remaining budget : %d\n", customer->budget);
printf("Thank you for Shopping with us!");
}
else {
printf("Error your budget has insufficant funds or Missing item\n");
printf("Thanks for shopping with us!\n");
}
}
int main() {
struct store store;
struct customer customer;
setupStore(&store);
setupCustomer(&customer);
Menu(&store);
char ItemChosen = Choice();
switch(ItemChosen) {
case 'A':
purchase(ItemChosen,store.Apple,&customer);
break;
case 'P':
purchase(ItemChosen,store.Pear,&customer);
break;
case 'O':
purchase(ItemChosen,store.Orange,&customer);
break;
default:
printf("Incorrect item [%c] selected.\n", ItemChosen);
printf("Thanks for shopping with us!\n");
break;
}
return 0;
}