#include <stdio.h>
void DisplayMenu(char *item);
void SetCost(char item, double *item_cost);
void MoneyMenu(double *bank, double item_cost);
int CheckMoney(double bank, double item_cost);
void GetMoney(double *bank, double item_cost, char item);
void GetChange(double *bank, double item_cost);
void Quit(char *again);
int main()
{
//Variable implanted to see if user wants to play again
char PlayAgain;
//Variable that decides what the user wants from menu
char ChoiceSelection;
//Variable that tells us the cost of item
double ItemCost;
//Variable that holds the bank balance
double BankBalance;
//initializes to zero as starting point
BankBalance=0;
//Variable that keeps track of user's money
//User starts with no money, so variable is initlize to zero
printf("Welcome to THE APP STORE.\n**********************************\n");
printf("You have $%.2lf in your bank\n\n", BankBalance);
DisplayMenu(&ChoiceSelection);
SetCost(ChoiceSelection, &ItemCost);
GetMoney(&BankBalance,ItemCost,ChoiceSelection);
GetChange(&BankBalance,ItemCost);
Quit(&PlayAgain);
printf("You have: $%.2lf credit available for next purchase.\n\n", BankBalance);
printf("\nThank you, enjoy your purchase(s).\n");
}
// Displays the list of apps available
//prompts for the user’s selection and sets the value of the selection
void DisplayMenu(char *item)
{
//Menu with costs
printf("HERE ARE THE SELECTION:\n");
printf("G -- GamePackage $4.99\n");
printf("X -- X-Ray App $2.99\n");
printf("E -- E-Bay Autobidder $7.99\n");
printf("R -- Restaurant Locator $1.99\n");
printf("P -- Photo editor $3.99\n");
//Asks for user's selection
printf("\nPlease enter a selection: ");
//User will enter their desired item
scanf(" %c", item);
}
//sets the cost of the item based on value stored in purchase
void SetCost(char item, double *item_cost)
{
//names set to equal to price
double GamePackagePrice=4.99;
double XRayAppPrice=2.99;
double EBayAutobidderPrice=7.99;
double RestaurantLocatorPrice=1.99;
double PhotoEditorPrice=3.99;
//if user enters G or g, the correct price is given
if(item=='G'||item=='g')
{
*item_cost=GamePackagePrice;
printf("The item you selected costs %.2f\n ",*item_cost);
}
//if user enters X or x, the correct price is given
else if(item=='X'||item=='x')
{
*item_cost=XRayAppPrice;
printf("The item you selected costs %.2f\n ",*item_cost);
}
//if user enters E or e, the correct price is given
else if(item=='E'||item=='e')
{
*item_cost=EBayAutobidderPrice;
printf("The item you selected costs %.2f\n ",*item_cost);
}
//if user enters R or r, the correct price is given
else if(item=='R'||item=='r')
{
*item_cost=RestaurantLocatorPrice;
printf("The item you selected costs %.2f\n ",*item_cost);
}
//if user enters P or p, the correct price is given
else if(item=='P'||item=='p')
{
*item_cost=PhotoEditorPrice;
printf("The item you selected costs %.2f\n ",*item_cost);
}
}
//Displays the codes for money input- gets user input amounts
//compares the int codes and updates the deposit amount
void MoneyMenu(double *bank, double item_cost)
{
int MoneyAmountWanted;
//Money Menu list that user choose in order to get money to buy item
printf("Please credit your bank balance by selecting from the menu:\n\n");
printf("--- 1 $10.00\n");
printf("--- 2 $5.00\n");
printf("--- 3 $2.00\n");
printf("--- 4 $1.00\n");
//scans how much they want
scanf("%d", &MoneyAmountWanted);
//if they picked 1, they will be credited 10 dollars
if(MoneyAmountWanted==1)
{
*bank=*bank+10;
}
//if they picked 2, they will be credited 5 dollars
else if(MoneyAmountWanted==2)
{
*bank=*bank+5;
}
//if they picked 3, they will be credited 2 dollars
else if(MoneyAmountWanted==3)
{
*bank=*bank+2;
}
//if they picked 4, they will be credited 1 dollar
else if(MoneyAmountWanted==4)
{
*bank=*bank+1;
}
}
//compares the amount the user has in deposits to the price of item selected.
//It returns 1 if the amount is enough to cover the cost, 0 if there is not enough.
int CheckMoney(double bank, double item_cost)
{
//if they have enough money to cover the cost of item, it returns 1 to let them buy
if(bank>=1)
{
return 1;
}
//if they don't have enough money to cover the cost of item, it returns 0 andd they will need to deposit more money
else
return;
}
//uses MoneyMenu function to display and collect dollar amounts from the user
//uses CheckMoney function to keep comparing the added deposited amount to the item cost.
void GetMoney(double *bank, double item_cost, char item)
{
MoneyMenu(bank,item_cost);
CheckMoney(*bank, item_cost);
printf("You have $%.2lf available in your bank.\n", *bank);
while(*bank<item_cost)
{
MoneyMenu(bank,item_cost);
CheckMoney(*bank, item_cost);
printf("You have $%.2lf available in your bank.\n", *bank);
}
printf("You have purchased: %c\n", item);
}
//calculates the amount of leftover from your deposits
void GetChange(double *bank, double item_cost)
{
*bank=*bank-item_cost;
return;
}
//Asks the user if they want another app
void Quit(char *again)
{
char ChoiceSelection;
printf("Would you like to make another purchase? ");
scanf(" %c", again);
if(*again=='y'||*again=='yes'||*again=='Y'||*again=='Yes')
{
DisplayMenu(&ChoiceSelection);
}
else if(*again=='n'||*again=='no'||*again=='N'||*again=='No')
{
return;
}
}