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

rchase lenons Purchase Sugar Sell Beverages Display Inventory Exi Selection: L n

ID: 3754145 • Letter: R

Question

rchase lenons Purchase Sugar Sell Beverages Display Inventory Exi Selection: L nter the nunber lenons te parchaset& elect one of the ellowingt Pure hase lenons B: Sel1 Beverages Display Inventory : Exi election:S Enter the nunber of pounds of sugar to purchase:1 elect one of the following a Purchase lenons Purchase Sugar : Sell Beverages Display Inventory electiont I nter the nunber of beverages that vere sold:1 elect one of the follouingt Purchase lenons : Sell Beverages Display Inventory election: tore Statistics unber of Beverages Seldi 1 Account: $6.88 r of Lenens in Stocki 3 Pounds of Sugar in Stock 1 1.9 lect one of the folloving R: Sell Beverages Selection:E Press any key to continue.. Purchase lenons Purchase Sugar Display Inventory Exit

Explanation / Answer

#include<stdio.h>
int main()
{
float account=0,sugar=5.9,val=100;
int lemon=9,brav=0,cs=-1;
char ch='';
while(cs!=0)
{
  val=-1; cs=0;ch='';
  
  printf(" Selecr one of the following: ");
  printf("L:Purchase Lemons. ");
  printf("S:Purchase Sugar. ");
  printf("B:Sell Beverages. ");
  printf("I:Display Inventory. ");
  printf("E:Exit. ");
  printf("Selection: ");
  fflush(stdin);
  scanf("%c",&ch);
  
  
  if(ch=='L')
  {
   cs=1;
  }
  if(ch=='S')
  {
   cs=2;
  }
  if(ch=='B')
  {
   cs=3;
  }
  if(ch=='I')
  {
   cs=4;
  }
  if(ch=='E')
  {
   cs=0;
  }
  switch(cs)
  {
   case 1:
    if(lemon!=0)
    {
     while(val>lemon||val<0)
     {
      printf(" Enter the number lemon to purchase(%d in stock): ",lemon);
      scanf("%f",&val);
     }
     lemon-=val;
     account+=(val*1);
    }
   break;
   case 2:
    if(sugar!=0)
    {
     while(val>sugar||val<0)
     {
      printf(" Enter the number of pound of sugar to purchase(%f in stock): ",sugar);
      scanf("%f",&val);
     }
     sugar-=val;
     account+=(val*0.88);
    }
   break;
   case 3:
    while(val<0)
    {
     printf(" Enter the number of Beverages that were sold: ");
     scanf("%f",&val);
    }
    brav+=val;
   break;
   case 4:
    printf(" Store Statistics");
    printf(" Account: $%.2f ",account);
    printf("Number of Beverages sold: %d ",brav);
    printf("Number of Lemon in stock: %d ",lemon);
    printf("Number of Sugar in stock: %.2f ",sugar);
   break;
  }
}

}