COP 2220 Help code this please. I need some help with this assignment. We went f
ID: 3605774 • Letter: C
Question
COP 2220 Help code this please.
I need some help with this assignment. We went from coding stuff like while loops in the main with less thant 50 lines of code to this assignment.
Intro to Programming in C – Large Programming Assignment 2 (apps.c) Assignment purpose: User defined functions, pointers, arrays, Menu driven program A Company needs to create software for their new line of phone Applications. Customers will have the opportunity to purchase the Apps using the following cash amounts: (1) - $1000.00, (2) - $500.00, (3) - $100.00 (4) - $10.00 L – LogMeIn Ignition $1399.99 V – VIP Black $999.99 F – Facetune $3.99 T– Tap Menu $399.99 M– Minecraft $6.99
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);
Sample OUTPUT:
Sample output:
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:
------------------------------
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:
------------------------------
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:
------------------------------
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:
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 4
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
Thank you, enjoy your purchase(s)
Press any key to continue . . .
These are the rules...
Please do only one step at a time and do not move onto the next step until you have compiled and tested the current step:
1. TAKE A LOOK AT THE PROGRAM SAMPLE OUTPUT AND run the application AND UNDERSTAND THE PROBLEM
2. WRITE THE ALGORITHM
3. create a project and name the source code apps.c
4. set up the program with header comment, preprocssor directives, main function
5. BUILD and TEST
6. set up the main yes or no loop with the function DoItAgain Use a while or do/while loop You may use tolower or toupper function from #include If you do not use tolower or toupper the contion for the loop will be either: char quit; //get a value for quit while(quit != 'N' && quit != 'n') OR while(quit == 'Y' || quit == 'y')
7. BUILD AND TEST with a different y and n options
8. Display the apps and get the app selection (DisplayApps function)
9. BUILD AND TEST with a few app selections
10. set the cost of the app that was selected by the user (SetCost function)
11. BUILD AND TEST with a few app choices
12. Start working on the Pay function There will be a loop in this function call the Compare function to check if there is enough money // initialization for the loop while there is not enough //the compare function returned a 0 //test for the loop { Present and get the money choice (1-4) and update the bank (PaymentOptions function) call the Compare function to check if there is enough money // update for the loop }
13. Make the function call to Pay and the function call to Compare USE printf statements to test the variable values
14. BUILD AND TEST build the loop slowly and add printf statements to test the values of the variables
15. BUILD AND TEST DO NOT CONTINUE UNTIL YOU ARE ABLE TO COMPLETE A PURCHASE !!!
16. Calculate the change back in the main function (GetChange function)
17. BUILD AND TEST
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 . . .