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

Intro to Programming in C - Programming Assignment 2 Assignment purpose: User de

ID: 3823040 • Letter: I

Question

Intro to Programming in C - Programming Assignment 2

Assignment purpose: User defined functions, pointers, 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) - $20.00, (2) - $10.00, (3) - $5.00 (4) - $2.00, (5) - $1.00

G – Graphing Calculator $14.95

M – Music Downloader $2.95

C – C programming guide $7.95

T – TxtToVoice $4.95

A – Astronomy Guide $5.95   

You must have at least 7 user defined functions:

// Displays the list of apps available

//prompts for the user’s selection and sets the value of the selection

void AppMenu(char *appChoicePtr);

//sets the cost of the item based on appChoice

void GetCost(char appChoice, double *appCostPtr);

//Displays the menu for the user to input money - gets user input amounts

//compares the int codes and updates the balance amount

void MoneyMenu(double *balancePtr, double appCost);

//compares the amount the user has in their balance 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 Enough(double balance, double appCost);

//uses MoneyMenu function to display and collect dollar amounts from the user

//uses Enough function to keep comparing the balance amount to the appcost.

void GetMoney(double *balancePtr, double appCost);   

//calculates the amount of leftover from balance after the purchase is made

void GetChange(double *balancePtr, double appCost);

//Asks the user if they want to buy another app

void Again(char *quitPtr);

SAMPLE OUTPUT:

Welcome to THE APP STORE

**********************************

You have $0.00 in your balance

-------------------------

HERE ARE THE SELECTIONS:

G – Graphing Calculator $14.95

M – Music Downloader $2.95

C – C programming guide $7.95

T – TxtToVoice $4.95

A – Astronomy Guide $5.95

Please enter a selection: G

------------------------------

You do not have enough in your balance

The item costs $14.95

You have $0.00 available in your balance

Please credit your balance by selection:

--- 1 $20.00

--- 2 $10.00

--- 3 $5.00

--- 4 $2.00

--- 5 $1.00

Deposit Amount: 2

------------------------------ You do not have enough in your balance

The item costs $14.95

You have $10.00 available in your balance

Please credit your balance by selection:

--- 1 $20.00

--- 2 $10.00

--- 3 $5.00

--- 4 $2.00

--- 5 $1.00

Deposit Amount: 5

------------------------------ You do not have enough in your balance

The item costs $14.95

You have $11.00 available in your balance

Please credit your balance by selection:
--- 1 $20.00

--- 2 $10.00

--- 3 $5.00

--- 4 $2.00

--- 5 $1.00

Deposit Amount: 3

You have purchased item: G

you have $1.05 left in your balance, would you like to make another purchase? y

**********************************

You have $1.05 in your balance

HERE ARE THE SELECTIONS:

G – Graphing Calculator $14.95

M – Music Downloader $2.95

C – C programming guide $7.95

T – TxtToVoice $4.95

A – Astronomy Guide $5.95


Please enter a selection: C

You do not have enough in your balance

The item costs $7.95

You have $1.05 available in your balance

Please credit your balance by selection:

--- 1 $20.00

--- 2 $10.00

--- 3 $5.00

--- 4 $2.00

--- 5 $1.00

Deposit Amount: 1


You have purchased: C

you have $13.10 left in your balance, would you like to make another purchase? n

you have: $13.10 credit available for next purchase

Thank you, enjoy your purchase(s)

Press any key to continue . . .

Explanation / Answer

Here is the code for you:

#include<stdio.h>
#define _CRT_SECURE_NO_WARNINGS
// Displays the list of apps available
//prompts for the user’s selection and sets the value of the selection
void AppMenu(char *appChoicePtr);
//sets the cost of the item based on value stored in purchase
void GetCost(char appChoice, double *appCostPtr);
//Displays the codes for money input- gets user input amounts
//compares the int codes and updates the deposit amount
void MoneyMenu(double *balancePtr);
//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 Enough(double balance, double appCost);
//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 *balancePtr);
//calculates the amount of leftover from your deposits
void GetChange(double *balancePtr, double appCost);
//Asks the user if they want another app
void Again(char *quitPtr);
int main()
{
char quit;
char appChoice = ' ';
double appCost;
double balance = 0;
printf("###### Welcome to the App Store ###### ");
printf("********************************** ");
printf("You have $0.00 in your balance ");
printf(" ------------------------------");
//initialize while loop
do {
//call menu
AppMenu(&appChoice);
  
       GetCost(appChoice, &appCost);
       while(!Enough(balance, appCost))
       {
          //printf(" You don't have enough in your balance");
          //call getcost
          //GetCost(appChoice, &appCost);
          printf(" That item costs $%.2f", appCost);
   //call getmoney
   printf(" You have $%.2f available in your balance", balance);
   GetMoney(&balance);
}
//call getchange
  
printf("You have purchased item: %c ", appChoice);
GetChange(&balance, appCost);
Again(&quit);
} while (quit == 'Y' || quit == 'y');
// while loop till quit is 'Y' OR quit is 'y'
//end while loop
printf(" Thank You!, Good Bye ");
return 0;
}
// Displays the list of apps available
//prompts for the user’s selection and sets the value of the selection
void AppMenu(char *appChoicePtr)
{
printf(" _____HERE ARE THE SELECTIONS_____ ");
printf(" G -- Graphic Calculator $14.95");
printf(" M -- Music Downloader $2.95");
printf(" C -- C programming guide $7.95");
printf(" T -- TxtToVoice $4.95");
printf(" A -- Astronomy Guide $5.95 ");
printf("Please enter a selection: ");
scanf(" %c", appChoicePtr);
}
//sets the cost of the item based on appChoice
void GetCost(char appChoice, double *appCostPtr)
{
//condition to update the selection made by the user
if (appChoice == 'M' || appChoice == 'm')
{
*appCostPtr = 2.95;
}
else if (appChoice == 'G' || appChoice == 'g')
{
*appCostPtr = 14.95;
}
else if (appChoice == 'C' || appChoice == 'c')
{
*appCostPtr = 7.95;
}
else if (appChoice == 'T' || appChoice == 't')
{
*appCostPtr = 4.95;
}
else if (appChoice == 'A' || appChoice == 'a')
{
*appCostPtr = 5.95;
}
}
//Displays the menu for the user to input money - gets user input amounts
//compares the int codes and updates the balance amount
void MoneyMenu(double *balancePtr)
{
int input = 1;
printf(" Please credit your money by making a selection: --- 1 $20.00 --- 2 $10.00 --- 3 $5.00 --- 4 $2.00 --- 5 $1.00 Deposit Amount: ");
scanf(" %d", &input);
//printf(" Deposit Amount: %d", input);
printf(" ------------------------------");
//display money choices
if (input == 1)
{
*balancePtr += 20.0;
}
else if (input == 2)
{
*balancePtr += 10.0;
}
else if (input == 3)
{
*balancePtr += 5.0;
}
else if (input == 4)
{
*balancePtr += 2.0;
}
else if (input == 5)
{
*balancePtr += 1.0;
}
}
//compares the amount the user has in their balance 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 Enough(double balance, double appCost)
{
//condition to check if money is enough to cover purchase
if (balance >= appCost)
{
return 1;
}
else if (balance < appCost)
{
printf(" You do not have enough in your balance");
return 0;
}
return 0;
}
//uses MoneyMenu function to display and collect dollar amounts from the user
//uses Enough function to keep comparing the balance amount to the appcost.
void GetMoney(double *balancePtr)
{
// call money menu
MoneyMenu(balancePtr);
//call check money
//Enough(*balancePtr, appCost);
}
//calculates the amount of leftover from balance after the purchase is made
void GetChange(double *balancePtr, double appCost)
{
double change = 0;
//calculate change left over from transaction
change = *balancePtr - appCost;
*balancePtr -= appCost;   //Updates the balance.
printf(" You have $%.2f left in your balance", change);
}
//Asks the user if they want to buy another app
void Again(char *quitPtr)
{
printf(" Would you like to make another purchase Y/N?: ");
scanf(" %c", quitPtr);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote