Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.90 KB | None | 0 0
  1. //Scott Albaz
  2. // 10/27/10
  3. //Joy Woodworth
  4. //Apps.c
  5. #define _CRT_SECURE_NO_DEPRECATE
  6. #include<stdio.h>
  7.  
  8.  
  9. // Displays the list of apps available
  10. //prompts for the user’s selection and sets the value of the selection
  11. void Menu(char *selection);
  12.  
  13. //sets the cost of the item based on value in selection
  14. void GetCost(char selection, double *item_cost);
  15.  
  16. //Displays the codes for money input- gets user input amounts
  17. //compares the int codes and updates the bank amount entered
  18. void MoneyMenu(double *bank, double item_cost);
  19.  
  20. //compares the amount the user has in the bank to the price of item selected.
  21. //It returns 1 if the amount is enough to cover the cost, 0 if there is not enough.
  22. int CheckMoney(double bank, double item_cost);
  23.  
  24. //uses MoneyMenu function to display and collect dollar amounts from the user
  25. //uses CheckMoney function to keep comparing the added deposited amount to the item cost.
  26. void GetMoney(double *bank, double item_cost, char selection);  
  27.  
  28. //calculates the amount of leftover in the bank
  29. void GetChange(double *bank, double item_cost);
  30.  
  31. //Asks the user if they want another app
  32. void Quit(char *again);
  33.  
  34.  
  35. int main()
  36. {   //declare var
  37.     char firstPurchase= ' ';
  38.     char selection= ' ';
  39.     double item_cost=0.0;
  40.     double bank=0.0;
  41.     char again= 'y';
  42.     //opening message and initial purchase question
  43.     printf("Welcome to the App Store!\n*******************************\nWould you like to make a new purchase?(Y/N):");
  44.     scanf(" %c", &firstPurchase);
  45.     //switch statement for for first purchase result
  46.     switch(firstPurchase)
  47.     {
  48.         case'Y':
  49.         case'y': printf("____________________________________________\n\n");
  50.                  break;
  51.  
  52.         case'N':
  53.         case'n': return 0;
  54.  
  55.         default: printf("Invalid Choice. Try Again.");
  56.     }
  57.     //loop if char again = y or Y
  58.     while(again=='y'||again=='Y')
  59.     {
  60.         //function calls
  61.         Menu( &selection);
  62.         GetCost( selection, &item_cost);
  63.         GetMoney(&bank, item_cost, selection);
  64.         Quit(&again);
  65.        
  66.     }
  67.        
  68.    
  69.    
  70. }
  71.  
  72. void Menu(char *selection)
  73. {
  74.     //prints choices and asks for input
  75.     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:");
  76.     scanf(" %c", selection);
  77. }
  78. void GetCost(char selection, double *item_cost)
  79. {
  80.     //sets value to item cost depending on choice
  81.     switch(selection)
  82.     {
  83.     case 'G':
  84.     case 'g':
  85.         *item_cost=4.99;
  86.         break;
  87.     case 'L':
  88.     case 'l':
  89.         *item_cost=1.99;
  90.         break;
  91.     case 'X':
  92.     case 'x':
  93.         *item_cost=12.99;
  94.         break;
  95.     case 'F':
  96.     case 'f':
  97.         *item_cost=15.99;
  98.         break;
  99.     case 'P':
  100.     case 'p':
  101.         *item_cost=9.99;
  102.         break;
  103.     default:
  104.         printf("Invalid Choice.");
  105.     }
  106. }
  107. void GetMoney(double *bank, double item_cost, char selection)
  108. {
  109.     /*problem is in here or in one of the sub-functions*/
  110.     //var to store return val from CheckMoney func.
  111.     int check_money_return=0;
  112.     //loop if bank is not greater than or equal to item_cost
  113.     while(check_money_return==0)
  114.     {
  115.         MoneyMenu(bank, item_cost);
  116.         check_money_return=CheckMoney(*bank, item_cost);
  117.        
  118.     }
  119.    
  120.  
  121. }
  122. void MoneyMenu(double *bank, double item_cost)
  123. {
  124.     //prints money choices and accumulates(?)
  125.     /*I'm not sure I made the accumulator correctly, i may have missed the lesson where you taught this*/
  126.  
  127.     double bank2=0;
  128.     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);
  129.     scanf("%lf", bank2);
  130.     *bank=*bank+bank2;
  131. }
  132.  
  133. int CheckMoney(double bank, double item_cost)
  134. {
  135.     //compares bank and item_cost
  136.     if(bank>=item_cost)
  137.     {
  138.         printf("This item costs $%.2f.\n\nYou have $%.2f in your bank",bank, item_cost);
  139.         return 1;
  140.     }
  141.     else
  142.     {
  143.         printf("You have $%.2f in your bank. You do NOT have enough money",bank);
  144.         return 0;
  145.     }
  146. }
  147.  
  148. void Quit(char *again)
  149. {
  150.     //asks for char again
  151.     printf("Would you like to make another purchase?(Y/N)");
  152.     scanf(" %c", again);
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement