Please create the following program in .c format using Visual Studio. You must h
ID: 3593274 • Letter: P
Question
Please create the following program in .c format using Visual Studio.
You must have at least 7 user defined functions as follows:
// Displays the list of apps available
//prompts for the user’s selection and sets the value of the selection
void DisplayApps(char *selectionPtr);
//sets the cost of the item based on value stored in purchase
void SetCost(char selection, double *costPtr);
//Displays the codes for the user to input money - gets user input amounts
//compares the int codes and updates the deposit amount
void PaymentOptions(double *depositPtr, double cost);
//compares the amount the user has in deposits to the price of app selected.
//It returns 1 if the amount is enough to cover the cost, 0 if there is not enough.
int Compare(double deposit, double choiceCost);
//uses PaymentOptions function to display and collect dollar amounts from the user
//uses Compare function to keep comparing the added deposited amount to the item cost.
void Pay(double *depositPtr, double choiceCost);
//calculates the amount of leftover from your deposits
void GetChange(double *depositPtr, double choiceCost);
//Asks the user if they want another app
void DoItAgain(char *quitPtr);
Program outline shown below.
Welcome to THE APP STORE
**********************************
You have $0.00 in your bank
-------------------------
HERE ARE THE SELECTIONS:
L -- LogmeIn Ignition $1399.99
V -- VIP Black $999.99
F -- Facetune $3.99
T -- Tap Menu $399.99
M -- Minecraft $6.99
Please enter a selection: l
------------------------------
You do not have enough in your bank
The item costs $1399.99
You have $0.00 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 2
------------------------------
You do not have enough in your bank
The item costs $1399.99
You have $500.00 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 2
------------------------------
You do not have enough in your bank
The item costs $1399.99 3 You have $1000.00 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 2
You have purchased: l
you have $100.01 left,
would you like to make another purchase?y
**********************************
You have $100.01 in your bank
-------------------------
HERE ARE THE SELECTIONS:
L -- LogmeIn Ignition $1399.99
V -- VIP Black $999.99
F -- Facetune $3.99
T -- Tap Menu $399.99
M -- Minecraft $6.99
Please enter a selection: f
You have purchased: f
you have $96.02 left, would you like to make another purchase?y
**********************************
You have $96.02 in your bank
-------------------------
HERE ARE THE SELECTIONS:
L -- LogmeIn Ignition $1399.99
V -- VIP Black $999.99
F -- Facetune $3.99
T -- Tap Menu $399.99
M -- Minecraft $6.99
Please enter a selection: t
------------------------------
You do not have enough in your bank
The item costs $399.99
You have $96.02 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 3
------------------------------
You do not have enough in your bank
The item costs $399.99
You have $196.02 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 3
------------------------------
You do not have enough in your bank
The item costs $399.99
You have $296.02 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 2
You have purchased: t
you have $396.03 left, would you like to make another purchase?n
you have: $396.03 credit available for next purchase T
hank you, enjoy your purchase(s) Press any key to continue . . .
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
// Displays the list of apps available
//prompts for the user’s selection and sets the value of the selection
void DisplayApps(char *selectionPtr)
{
//Displays the main menu
printf(" -------------------------");
printf(" HERE ARE THE SELECTIONS: ");
printf(" L -- LogmeIn Ignition $1399.99");
printf(" V -- VIP Black $999.99");
printf(" F -- Facetune $3.99");
printf(" T -- Tap Menu $399.99");
printf(" M -- Minecraft $6.99");
fflush(stdin);
//Accepts user choice for item
printf(" Please enter a selection: ");
scanf("%c", selectionPtr);
printf(" ------------------------------");
}//End of function
//Sets the cost of the item based on value stored in purchase
void SetCost(char selection, double *costPtr)
{
//Checks Item and sets the price
switch(selection)
{
case 'l':
case 'L':
*costPtr = 1399.99;
break;
case 'v':
case 'V':
*costPtr = 999.99;
break;
case 'f':
case 'F':
*costPtr = 3.99;
break;
case 't':
case 'T':
*costPtr = 399.99;
break;
case 'm':
case 'M':
*costPtr = 6.99;
break;
default:
printf(" Invalid choice!");
}//End of switch - chase
}//End of function
//Function to display deposit menu
void depositMenu(int *choice)
{
//Displays deposit menu
printf(" --- 1 $1000.00");
printf(" --- 2 $500.00");
printf(" --- 3 $100.00");
printf(" --- 4 $10.00");
printf(" Deposit Amount: ");
fflush(stdin);
//Accepts user choice
scanf("%d", choice);
printf(" ---------------------------------------");
}//End of function
//Displays the codes for the user to input money - gets user input amounts
//compares the int codes and updates the deposit amount
void PaymentOptions(double *depositPtr, double cost)
{
int choice;
//Displays information
printf(" You do not have enough in your bank");
printf(" The item costs %.2f ", cost);
printf(" You have %.2f available in your bank ", *depositPtr);
printf(" Please credit your money by selection: ");
//Calls the function to display deposit choice and accept it
depositMenu(&choice);
//Adds deposit amount as per user choice for deposit
switch(choice)
{
case 1:
*depositPtr += 1000;
break;
case 2:
*depositPtr += 500;
break;
case 3:
*depositPtr += 100;
break;
case 4:
*depositPtr += 10;
break;
default:
printf(" Invalid choice!");
}//End of switch - case
}//End of function
//compares the amount the user has in deposits to the price of app selected.
//It returns 1 if the amount is enough to cover the cost, 0 if there is not enough.
int Compare(double deposit, double choiceCost)
{
//Compares if deposit amount is greater than choice cost then return one
if(deposit >= choiceCost)
return 1;
//Otherwise return zero
else
return 0;
}//End of function
//uses PaymentOptions function to display and collect dollar amounts from the user
//uses Compare function to keep comparing the added deposited amount to the item cost.
void Pay(double *depositPtr, double choiceCost)
{
//Loops till deposit amount is greater than the choice cost
do
{
//Calls the method to compare deposit amount with choice cost if it is less then calls PaymentOptions function for deposit
if(!Compare(*depositPtr, choiceCost))
PaymentOptions(depositPtr, choiceCost);
//Otherwise calls GetChange method for purchase
else
{
GetChange(depositPtr, choiceCost);
//Come out of the loop
break;
}//End of else
}while(1); //End of do - while loop
}//End of function
//calculates the amount of leftover from your deposits
void GetChange(double *depositPtr, double choiceCost)
{
//Subtracts choice cost from the deposit amount
*depositPtr = *depositPtr - choiceCost;
}//End of function
//Asks the user if they want another app
void DoItAgain(char *quitPtr)
{
fflush(stdin);
//Accepts user choice for continue or not
printf(" Would you like to make another purchase? ");
scanf("%c", quitPtr);
printf(" *****************************");
}//End of function
//Main function definition
int main()
{
printf(" Welcome to THE APP STORE");
printf(" **********************************");
char select;
double cost = 0;
double deposit;
double choiceCost;
char quit;
//Loops till user choice is not 'n' or 'N'
do
{
//Calls the function to select the item to purchase
DisplayApps(&select);
//Calls the function to set the cost of the product
SetCost(select, &cost);
//Calls the function for purchase
Pay(&deposit, cost);
printf(" You have purchased: %c", select);
printf(" you have %f left", deposit);
//Calls the function to check whether to continue or not
DoItAgain(&quit);
printf(" You have %.2f in your bank", deposit);
//Checks if choice is 'n' or 'N' display the message and stop
if(quit == 'n' || quit == 'N')
{
printf(" You have: %.2f credit available for next purchase ");
printf(" Thank you, enjoy your purchase(s) Press any key to continue . . .");
break;
exit(0);
}//End of if
}while(1);//End of do - while
}//End of main function
Sample Run:
Welcome to THE APP STORE
**********************************
-------------------------
HERE ARE THE SELECTIONS:
L -- LogmeIn Ignition $1399.99
V -- VIP Black $999.99
F -- Facetune $3.99
T -- Tap Menu $399.99
M -- Minecraft $6.99
Please enter a selection: L
------------------------------
You do not have enough in your bank
The item costs 1399.99
You have 0.00 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 2
---------------------------------------
You do not have enough in your bank
The item costs 1399.99
You have 500.00 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 2
---------------------------------------
You do not have enough in your bank
The item costs 1399.99
You have 1000.00 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 2
---------------------------------------
You have purchased: L
you have 100.010000 left
Would you like to make another purchase? y
*****************************
You have 100.01 in your bank
-------------------------
HERE ARE THE SELECTIONS:
L -- LogmeIn Ignition $1399.99
V -- VIP Black $999.99
F -- Facetune $3.99
T -- Tap Menu $399.99
M -- Minecraft $6.99
Please enter a selection: f
------------------------------
You have purchased: f
you have 96.020000 left
Would you like to make another purchase? y
*****************************
You have 96.02 in your bank
-------------------------
HERE ARE THE SELECTIONS:
L -- LogmeIn Ignition $1399.99
V -- VIP Black $999.99
F -- Facetune $3.99
T -- Tap Menu $399.99
M -- Minecraft $6.99
Please enter a selection: t
------------------------------
You do not have enough in your bank
The item costs 399.99
You have 96.02 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 3
---------------------------------------
You do not have enough in your bank
The item costs 399.99
You have 196.02 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 3
---------------------------------------
You do not have enough in your bank
The item costs 399.99
You have 296.02 available in your bank
Please credit your money by selection:
--- 1 $1000.00
--- 2 $500.00
--- 3 $100.00
--- 4 $10.00
Deposit Amount: 2
---------------------------------------
You have purchased: t
you have 396.030000 left
Would you like to make another purchase? n
*****************************
You have 396.03 in your bank
You have: 396.03 credit available for next purchase
Thank you, enjoy your purchase(s) Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.