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

Customer is asked how much currency they have available which is stored to a glo

ID: 3817751 • Letter: C

Question

Customer is asked how much currency they have available which is stored to a global variable and displayed when they purchase. Program explains how all shops are closed other than the one you create. Program asks if the customer (the user) wants to enter the open shop. (If they don't, the program exits.) Program introduces the shop and displays the available items and how much each costs (Minimum of 4 items) Customer is asked to pick an item from the list to purchase. If the customer picks an item not on the list, they are told that item doesn't exist or is no longer available and are asked to Additionally, a final option under available items is available to exit the store. If the customer has enough currency, the item's cost is deducted from their total currency and the purchased item is removed from the available items. If the customer doesn't have enough currency, they are told to try another item. Program then outputs the item which was purchased and the remaining currency the customer has left. After a purchase is made, they are shown the new list of items available (with the one they bought no longer available) to buy more. If all items have been purchased, the store closes. Find pieces/chunks of your code with "repeating patterns' which can be converted into void functions. See the pre-lab for a good example. A double colon before a variable name will access the global variable with that name. 1.e currency Pieces of your program such as listing items or responding to an item purchase are good candidates for void functions.

Explanation / Answer

#include<iostream.h>
#include<conio.h>

#include<string.h>

double Currency=100;
string Items[4]={"Chips","Pepsi","Chocolate","Biscuit"};
int Price[4]={10,20,30,40};
int Qty[4]={5,5,5,5};
int shop()
{
   int choice;
   cout<<"Welcome to Walmart!!!"<<endl;
   for(int i=1;i<5;i++)
   {
       cout<<i<<"."<<Items[i]<<" $"<<Price[i]<<endl;
   }
   cout<<"Please make a choice"<<endl;
   cin>>choice;
   switch(choice)
   {
       case 1 : if(Qty[1] != 0)
           {
               if(Currency>Price[1])
               {
                   cout<<"Thanks for purchasing Chips!"<<endl;
                   Currency = Currency - Price[1];
                   Qty[1] = Qty[1]-1;
                   Cout<<"You have $"<<Currency<<" left"<<endl;
               }
               else
                   cout<<"Try another item"<<endl;
           }
           else
               cout<<"Item Doesnot exist!"<<endl;
           break;
       case 2 : if(Qty[2] != 0)
           {
               if(Currency>Price[2])
               {
                   cout<<"Thanks for purchasing Chips!"<<endl;
                   Currency = Currency - Price[2];
                   Qty[2] = Qty[2]-1;
                   Cout<<"You have $"<<Currency<<" left"<<endl;
               }
               else
                   cout<<"Try another item"<<endl;
              
           }
           else
               cout<<"Item Doesnot exist!"<<endl;
           break;
       case 3 : if(Qty[3] != 0)
           {
               if(Currency>Price[3])
               {
                   cout<<"Thanks for purchasing Chips!"<<endl;
                   Currency = Currency - Price[3];
                   Qty[3] = Qty[3]-1;
                   Cout<<"You have $"<<Currency<<" left"<<endl;
               }
               else
                   cout<<"Try another item"<<endl;   Qty[2] = Qty[2]-1;
           }
           else
               cout<<"Item Doesnot exist!"<<endl;
           break;
       case 4 : if(Qty[4] != 0)
           {
               if(Currency>Price[4])
               {
                   cout<<"Thanks for purchasing Chips!"<<endl;
                   Currency = Currency - Price[4];
                   Qty[4] = Qty[4]-1;
                   Cout<<"You have $"<<Currency<<" left"<<endl;
               }
               else
                   cout<<"Try another item"<<endl;  
           }
           else
               cout<<"Item Doesnot exist!"<<endl;
           break;
}
int main()
{
   char ans;
   cout<<"How much currency do you have ?"<<endl;
   cout<<"I have $"<<Currency<<endl;
   cout<<"Do you want to enter the open shop(Y/N)?"<<endl;
   cin>>ans;
   if(ans == 'Y' || ans == 'y')
   {
       Shop();
   }
   else
       exit(1);
   return(0);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote