Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

00 Sprint 12:20 PM Close Project-1 Project-1 Specifications A Company needs to c

ID: 3604520 • Letter: 0

Question

00 Sprint 12:20 PM Close Project-1 Project-1 Specifications 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: Cash Amounts that can be deposited 1. $1000.00 2. $500.00 3. $100.00 4. $10.00 App List and Prices 299.99 C- Clown Punching V-Virtual Snow Globe R - Remote PC G- Grocery List Helper M- Mobile Cam Viewer S349.99 $999.99 $2.99 $89.99 Use Case 1 (Inadequate Balance) 1. User opens the App and is greeted and the amount of money in the bank is displayed. 2. List of available Apps is displayed. 3. User selects an App to purchase 4. If user does not have enough money, she is

Explanation / Answer

#include <stdio.h>

// Displays list of apps available prompts for user selection

// and sets the value of the selection

void displayApps(char *pSelection);

// Sets the cost of the item based on the value stored in purchase

void setCost(char selection,double *pCost);

// Displays the codes for users to input money - gets user inputs

// and updates deposit amount

void paymentOptions(double *pDeposit,double cost);

// Compares the amount user has in deposits to the price of app selected

// Returns 1 if the amount is enough to cover the cost else returns 0

int compare(double deposit,double choiceCost);

// Uses paymentOptions function to get deposit amounts from users and keeps checking if the added amount

// can cover the item cost. If so payment is made

void pay(double *pDeposit,double choiceCost);

// Calculates the amount leftover from the deposits

void getChange(double *pDeposit,double choiceCost);

// Asks the user if they want another app

void doItAgain(char *pQuit);

int main(){

printf("Welcome to THE APP STORE ");

printf("*************************** ");

double deposit=0.00;

printf("You have $%lf in your bank ",deposit);

char cont='y';

while(cont == 'y'){

char selection;

displayApps(&selection);

double cost;

setCost(selection,&cost);

pay(&deposit,cost);

doItAgain(&cont);

}

return 0;

}

// Displays list of apps available prompts for user selection

// and sets the value of the selection

void displayApps(char *pSelection){

printf("HERE ARE THE SELECTIONS ");

printf("C-Clown Punching $299.99 ");

printf("V-Virtual Snow Globe $349.99 ");

printf("R-Remote PC $999.99 ");

printf("G-Grocery List Helper $2.99 ");

printf("M-Mobile Cam Viewer $89.99 ");

printf("Please make a selection ");

char selection;

// Added a 'space' in front of %c to avoid scanning 'enter' and 'space'

scanf(" %c",&selection);

*pSelection = selection;

return;

}

// Sets the cost of the item based on the value stored in purchase

void setCost(char selection,double *pCost){

int prices[] = {299.99,349.99,999.99,2.99,89.99};

switch(selection){

case 'C':

*pCost = prices[0];

break;

case 'V':

*pCost = prices[1];

break;

case 'R':

*pCost = prices[2];

break;

case 'G':

*pCost = prices[3];

break;

case 'M':

*pCost = prices[4];

break;

}

return;

}

// Displays the codes for users to input money - gets user inputs

// and updates deposit amount

void paymentOptions(double *pDeposit,double cost){

printf("Please add atleast %lf to continue ",cost-*pDeposit);

printf("Pick the choice of money you wish to deposit ");

printf("1. $1000.00, ");

printf("2. $500.00, ");

printf("3. $100.00, ");

printf("4. $10.00 ");

int pref;

// Added a 'space' in front of %c to avoid scanning 'enter' and 'space'

scanf("%d",&pref);

if(pref == 1) *pDeposit += 1000.00;

else if(pref == 2) *pDeposit += 500.00;

else if(pref == 3) *pDeposit += 100.00;

else if(pref == 4) *pDeposit += 10.00;

printf("Your updated balance is $%lf ",*pDeposit);

return;

}

// Compares the amount user has in deposits to the price of app selected

// Returns 1 if the amount is enough to cover the cost else returns 0

int compare(double deposit,double choiceCost){

if(deposit >= choiceCost)

return 1;

else

return 0;

}

// Uses paymentOptions function to get deposit amounts from users and keeps checking if the added amount

// can cover the item cost. If so payment is made

void pay(double *pDeposit,double choiceCost){

if(compare(*pDeposit,choiceCost) == 1){

getChange(pDeposit,choiceCost);

}else{

paymentOptions(pDeposit,choiceCost);

pay(pDeposit,choiceCost);

}

return;

}

// Calculates the amount leftover from the deposits

void getChange(double *pDeposit,double choiceCost){

*pDeposit -= choiceCost;

printf("Your remaining balance is $%lf ",*pDeposit);

return;

}

// Asks the user if they want another app

void doItAgain(char *pQuit){

printf("Do you purchase another app (y/n) ? ");

char ch;

// Added a 'space' in front of %c to avoid scanning 'enter' and 'space'

scanf(" %c",&ch);

*pQuit = ch;

return;

}