Write a Menu driven algorithm program "online purchase system” to allow the following options of
transaction, Assume that you are maintaining the account balance of Rs.X (Get 'x' from
user).
Case 1: Purchasing an item, following conditions need to be checked before
confirming the item cart
→ The amount is detected from balance- The customer should have sufficient
amount as balance or necessary error message need to be displayed.
Case 2: Returning the item
→ The item cost is added back to balance.
→ If the item not returned within 10 days of time, Rs. 10/day charge to be
detected from the balance amount
Case 3: Referring a friend
→ When you refer a friend to the online store, you will get a bonus amount of
Rs.20/person in the balance.
You have to do the operations mentioned above until user wants to continue to do
so (Sentinel - Control loop)
Answers
Answer:
...................
Program :
#include<iostream>
using namespace std;
int main()
{
int X , ch , P;
cout<<"Enter the account balance : ";
cin>>X;
cout<<"Enter 0 : To Exit\nEnter 1 : To purchase an item\nEnter 2 : To return an item\nEnter 3 : Referring a friend\nEnter your choice : ";
cin>>ch;
while(ch!=0)
{
if(ch == 1 || ch == 2)
{
cout<<"Enter the cost of the product: ";
cin>>P;
}
switch(ch)
{
case 1:
if(X>P)
{
X = X - P;
cout<<"Your Balance : "<<X<<endl;
}
else
{
cout<<"You have insufficient balance : ";
cout<<"\nYour Balance : "<<X<<endl;
}
break;
case 2:
X = X + P;
cout<<"Your Balance : "<<X<<endl;
break;
case 3:
X = X + 20;
cout<<"Your Balance : "<<X<<endl;
break;
default :
cout<<"Invalid Choice\n";
}
cout<<"Enter 0 : To Exit\nEnter 1 : To purchase an item\nEnter 2 : To return an item\nEnter 3 : Referring a friend\nEnter your choice : ";
cin>>ch;
}
return 0;
}