title: Difficulty writing a loop basing on user choice
body: <p>I'm having difficulty writing a loop that will ask a user if he/she wants to continue the purchase of the products. It's part of my coursework at school. I have written all the required functions but Im struggling to get the loop to work.</p>
  <p>Basically, what I want the loop to do is ask a user if he/she wants to continue the purchase and the answer should be either Y or N. Which will then take the remaining budget, implement it back to the program and run it again with that budget in mind, then deduct the value of the product chosen.</p>
  <p>I have been trying to write that loop for more than 2 hours now and I'm running out of ideas.</p>
  <p>That's the code I'm working with:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int getItemPrice(char itemPrefix, int applePrice, int orangePrice, int pearPrice);
  displayMenu(int applePrice, int orangePrice, int pearPrice);
  withinBudget(int budget, char purchase, int applePrice, int orangePrice, int pearPrice);
  purchaseItem(int budget, char purchase, int applePrice, int orangePrice, int pearPrice);
  
  int main()
  {
      
      int orangePrice, applePrice, pearPrice, budget; 
      char purchase;                                      
      printf(&quot;*****************\n&quot;);
      printf(&quot;Item prefixes\n&quot;);
      printf(&quot;A: Apple\n&quot;);
      printf(&quot;O: Orange\n&quot;);
      printf(&quot;P: Pear\n&quot;);
      printf(&quot;*****************\n\n&quot;);
  
      
      printf(&quot;***************\n&quot;);
      printf(&quot;*** MyStore ***\n&quot;);
      printf(&quot;***************\n\n&quot;);
      
      printf(&quot;**** SHOPKEEPER PANEL ****\n&quot;);
  
      printf(&quot;Welcome to the store. Please enter the prices for the following products: \n&quot;);
      printf(&quot;Please enter the price for the Orange: \x9C&quot;);
      scanf_s(&quot;%d&quot;, &amp;orangePrice);
      printf(&quot;Please enter the price for the Apple: \x9C&quot;);
      scanf_s(&quot;%d&quot;, &amp;applePrice); 
      printf(&quot;Please enter the price for the Pear: \x9C&quot;);
      scanf_s(&quot;%d&quot;, &amp;pearPrice);  
      printf(&quot;\n\n&quot;);
  
      displayMenu(applePrice, orangePrice, pearPrice);
      
      printf(&quot;**** Customer menu ****\n&quot;);
      printf(&quot;Please enter your budget: \x9C&quot;);
      scanf_s(&quot;%d&quot;, &amp;budget);
      printf(&quot;Please enter the item you would like to purchase using the item Prefix: &quot;);
      scanf_s(&quot; %c&quot;, &amp;purchase, 1);
      printf(&quot;\n\n&quot;);
  
      displayMenu(applePrice, orangePrice, pearPrice);
  
      withinBudget(budget, purchase, applePrice, orangePrice, pearPrice);
  
      purchaseItem(budget, purchase, applePrice, orangePrice, pearPrice);
  
      return 0;
  };
  
  int getItemPrice(char itemPrefix, int applePrice, int orangePrice, int pearPrice)
  {
  
      if (itemPrefix == 'A') {
          return applePrice; 
      }
      else if (itemPrefix == 'O') {
          return orangePrice; 
      }
      else if (itemPrefix == 'P') {
          return pearPrice;
      }
      else {
          return -1;  
      }
  
      return getItemPrice;
  }
  
  displayMenu(int applePrice, int orangePrice, int pearPrice)
  {
      
      printf(&quot;**** Shop Menu ****\n&quot;);
      printf(&quot;Item:\t\tPrice\n&quot;);
      printf(&quot;A:\t\t\x9C%d\n&quot;, applePrice);   
      printf(&quot;O:\t\t\x9C%d\n&quot;, orangePrice);  
      printf(&quot;P:\t\t\x9C%d\n&quot;, pearPrice);    
      printf(&quot;\n\n&quot;);
      return 0;
  }
  withinBudget(int budget, char purchase, int applePrice, int orangePrice, int pearPrice)
  {
      int getItemPrice(itemPrefix, applePrice, orangePrice, pearPrice);
  
      if (purchase == 'A') {
          return applePrice;
      }
      else if (purchase == 'O') {
          return orangePrice; 
      }
      else if (purchase == 'P') {
          return pearPrice;
      }
      else {
          return -1;
      }
  }
  purchaseItem(int budget, char purchase, int applePrice, int orangePrice, int pearPrice)
  {
  
      int items ;
      int calculation;
  
      if (purchase == 'A') {
          items = applePrice; 
      }
      else if (purchase == 'O') {
          items = orangePrice;
      }
      else if (purchase == 'P') {
          items = pearPrice;  
      }
      else {
          items = -1; 
      }
  
      if (items != -1) {
          calculation = budget - items;
          if (calculation &gt;= 0) { 
              printf(&quot;Purchase was a success!\n&quot;);
              printf(&quot;Purchase details\n&quot;);
              printf(&quot;----------------------\n&quot;);
              printf(&quot;Item: %c\n&quot;, purchase);
              printf(&quot;Price: \x9C%d\n&quot;, items);
              printf(&quot;Remaining budget: \x9C%d\n\n&quot;, calculation);
              printf(&quot;Thanks for shopping with us!&quot;);
          }
          else {  
              items = -1;
          }
      }
      if (items == -1) {  
          printf(&quot;Purchase FAILED!\n&quot;);
          printf(&quot;Low budget or invalid item!\n\n&quot;);
          printf(&quot;Thanks for shopping with us!&quot;);
      }
  ;
  </code></pre>
  <p>I have already tried writing the while loop in the body of the program as well as inside of the purchase item function. I'm completely clueless at this point and don't really know what can I do to make it work. Or what I'm not doing that would help me this program to work as I  want it to.</p>
  <p>Any help would be appreciated. As well as any tips on what can I do to improve it.</p>