hi there, I fixed most of the errors in my program appstore and it runs fine for
ID: 3798501 • Letter: H
Question
hi there,
I fixed most of the errors in my program appstore and it runs fine for the first transaction. However, it only does one transaction and it quits afterwards. my c program supposed to be an appstore that continues to do more than transaction. how can i continue my program from stopping after one transaction? please help. here is my code.
#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, double appCost);
//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, double appCost);
//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 ");
//call Quit
Again(&quit);
//initialize while loop
do {
//call menu
AppMenu(&appChoice);
printf("You selected: %c", appChoice);
//call getcost
GetCost(appChoice, &appCost);
printf(" That item costs $%.2f", appCost);
//call getmoney
GetMoney(&balance, appCost);
printf(" Your current balance is $%.2f", balance);
//call getchange
GetChange(&balance, appCost);
Again(&quit);
} while (quit == 'Y' &&quit == 'y');
//end while loop
printf(" Thank You!, Good Bye ");
return 0;
}
void AppMenu(char *appChoicePtr)
{
printf(" _____PLEASE MAKE A SELECTION_____ ");
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 >>>");
scanf_s(" %c", appChoicePtr);
}
void MoneyMenu(double *balancePtr, double appCost)
{
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 Selection: ");
scanf_s(" %d", &input);
printf(" You have entered: %d", input);
//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;
}
}
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;
}
}
void GetMoney(double *balancePtr, double appCost)
{
// call money menu
MoneyMenu(balancePtr, appCost);
//call check money
Enough(*balancePtr, appCost);
}
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(" Insufficient funds, you need to add more money");
return 0;
}
return 0;
}
void GetChange(double *balancePtr, double appCost)
{
double change = 0;
//calculate change left over from transaction
change = *balancePtr - appCost;
printf(" You have...$%.2f", change);
}
void Again(char *quitPtr)
{
printf(" Would you like to buy an app Y/N?: ");
scanf_s(" %c", quitPtr);
}
Explanation / Answer
#include <stdio.h>
// 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, double appCost);
//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, double appCost);
//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 ");
//call Quit
Again(&quit);
//initialize while loop
do {
//call menu
AppMenu(&appChoice);
printf("You selected: %c", appChoice);
//call getcost
GetCost(appChoice, &appCost);
printf(" That item costs $%.2f", appCost);
//call getmoney
GetMoney(&balance, appCost);
printf(" Your current balance is $%.2f", balance);
//call getchange
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;
}
void AppMenu(char *appChoicePtr)
{
printf(" _____PLEASE MAKE A SELECTION_____ ");
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 >>>");
scanf(" %c", appChoicePtr);
}
void MoneyMenu(double *balancePtr, double appCost)
{
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 Selection: ");
scanf(" %d", &input);
printf(" You have entered: %d", input);
//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;
}
}
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;
}
}
void GetMoney(double *balancePtr, double appCost)
{
// call money menu
MoneyMenu(balancePtr, appCost);
//call check money
Enough(*balancePtr, appCost);
}
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(" Insufficient funds, you need to add more money");
return 0;
}
return 0;
}
void GetChange(double *balancePtr, double appCost)
{
double change = 0;
//calculate change left over from transaction
change = *balancePtr - appCost;
printf(" You have...$%.2f", change);
}
void Again(char *quitPtr)
{
printf(" Would you like to buy an app Y/N?: ");
scanf(" %c", quitPtr);
}
/*
output:
###### Welcome to the App Store ######
**********************************
You have $0.00 in your balance
Would you like to buy an app Y/N?: Y
_____PLEASE MAKE A SELECTION_____
G -- Graphic Calculator $14.95
M -- Music Downloader $2.95
C -- C programming guide $7.95
T -- TxtToVoice $4.95
A -- Astronomy Guide $5.95
>>>G
You selected: G
That item costs $14.95
Please credit your money by making a selection:
--- 1 $20.00
--- 2 $10.00
--- 3 $5.00
--- 4 $2.00
--- 5 $1.00
Deposit Selection: 1
You have entered: 1
Your current balance is $20.00
You have...$5.05
Would you like to buy an app Y/N?: Y
_____PLEASE MAKE A SELECTION_____
G -- Graphic Calculator $14.95
M -- Music Downloader $2.95
C -- C programming guide $7.95
T -- TxtToVoice $4.95
A -- Astronomy Guide $5.95
>>>M
You selected: M
That item costs $2.95
Please credit your money by making a selection:
--- 1 $20.00
--- 2 $10.00
--- 3 $5.00
--- 4 $2.00
--- 5 $1.00
Deposit Selection: 1
You have entered: 1
Your current balance is $40.00
You have...$37.05
Would you like to buy an app Y/N?: Y
_____PLEASE MAKE A SELECTION_____
G -- Graphic Calculator $14.95
M -- Music Downloader $2.95
C -- C programming guide $7.95
T -- TxtToVoice $4.95
A -- Astronomy Guide $5.95
>>>C
You selected: C
That item costs $7.95
Please credit your money by making a selection:
--- 1 $20.00
--- 2 $10.00
--- 3 $5.00
--- 4 $2.00
--- 5 $1.00
Deposit Selection: 1
You have entered: 1
Your current balance is $60.00
You have...$52.05
Would you like to buy an app Y/N?: N
Thank You!, Good Bye
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.