Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Scott Albaz
- // 10/27/10
- //Joy Woodworth
- //Apps.c
- #define _CRT_SECURE_NO_DEPRECATE
- #include<stdio.h>
- // Displays the list of apps available
- //prompts for the user’s selection and sets the value of the selection
- void Menu(char *selection);
- //sets the cost of the item based on value in selection
- void GetCost(char selection, double *item_cost);
- //Displays the codes for money input- gets user input amounts
- //compares the int codes and updates the bank amount entered
- void MoneyMenu(double *bank, double item_cost);
- //compares the amount the user has in the bank 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 CheckMoney(double bank, double item_cost);
- //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 *bank, double item_cost, char selection);
- //calculates the amount of leftover in the bank
- void GetChange(double *bank, double item_cost);
- //Asks the user if they want another app
- void Quit(char *again);
- int main()
- { //declare var
- char firstPurchase= ' ';
- char selection= ' ';
- double item_cost=0.0;
- double bank=0.0;
- char again= 'y';
- //opening message and initial purchase question
- printf("Welcome to the App Store!\n*******************************\nWould you like to make a new purchase?(Y/N):");
- scanf(" %c", &firstPurchase);
- //switch statement for for first purchase result
- switch(firstPurchase)
- {
- case'Y':
- case'y': printf("____________________________________________\n\n");
- break;
- case'N':
- case'n': return 0;
- default: printf("Invalid Choice. Try Again.");
- }
- //loop if char again = y or Y
- while(again=='y'||again=='Y')
- {
- //function calls
- Menu( &selection);
- GetCost( selection, &item_cost);
- GetMoney(&bank, item_cost, selection);
- Quit(&again);
- }
- }
- void Menu(char *selection)
- {
- //prints choices and asks for input
- printf("HERE ARE YOUUR CHOICES\nG -- GPS Locator $4.99\nL -- Flashlight $1.99\nF -- Food Replicator $15.99\nP -- Game Package $9.99\n\nPlease ente a selection:");
- scanf(" %c", selection);
- }
- void GetCost(char selection, double *item_cost)
- {
- //sets value to item cost depending on choice
- switch(selection)
- {
- case 'G':
- case 'g':
- *item_cost=4.99;
- break;
- case 'L':
- case 'l':
- *item_cost=1.99;
- break;
- case 'X':
- case 'x':
- *item_cost=12.99;
- break;
- case 'F':
- case 'f':
- *item_cost=15.99;
- break;
- case 'P':
- case 'p':
- *item_cost=9.99;
- break;
- default:
- printf("Invalid Choice.");
- }
- }
- void GetMoney(double *bank, double item_cost, char selection)
- {
- /*problem is in here or in one of the sub-functions*/
- //var to store return val from CheckMoney func.
- int check_money_return=0;
- //loop if bank is not greater than or equal to item_cost
- while(check_money_return==0)
- {
- MoneyMenu(bank, item_cost);
- check_money_return=CheckMoney(*bank, item_cost);
- }
- }
- void MoneyMenu(double *bank, double item_cost)
- {
- //prints money choices and accumulates(?)
- /*I'm not sure I made the accumulator correctly, i may have missed the lesson where you taught this*/
- double bank2=0;
- printf("You have $%.2f in your bank\n\nPlease credit your money by selection:\n--20 $20.00\n--10 $10.00\n--5 $5.00\n--1 $1.00\nDeposit Amount:", bank);
- scanf("%lf", bank2);
- *bank=*bank+bank2;
- }
- int CheckMoney(double bank, double item_cost)
- {
- //compares bank and item_cost
- if(bank>=item_cost)
- {
- printf("This item costs $%.2f.\n\nYou have $%.2f in your bank",bank, item_cost);
- return 1;
- }
- else
- {
- printf("You have $%.2f in your bank. You do NOT have enough money",bank);
- return 0;
- }
- }
- void Quit(char *again)
- {
- //asks for char again
- printf("Would you like to make another purchase?(Y/N)");
- scanf(" %c", again);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement