Page 458 - C++
P. 458
int temp,i,quant[no];
for(i=0;name[i][0]!='\0';i++)
quant[i]=0;
float amount=0;
clrscr();
do{cout<<"\n\t\t\tWelcome customer!\n\n";
universal.display();
cout<<"\n\n\t\t\t What do you want to do?\n\n\t\t(1)Add to
cart\t\t(2)Remove from cart\n\n\t\t(3)View cart\t\t(4)Exit";
choice=getch();
switch(choice)
{case '1': cout<<"\n\n\t\t\t Add to cart\n\n Enter item code:";
cin>>temp;
for(i=0;name[i][0]!='\0'&&temp!=code[i];i++);
if(code[i]==temp)
{cout<<"\n Enter quantity:";
cin>>quant[i];
amount+=quant[i]*price[i];
amount+=tax(amount)+vat(amount);
cout<<"\n\t\t\t Added to the cart";}
else
cout<<"\n\t\t\t\a Code not found";
getch();
break;
case '2': cout<<"\n\n Enter code of the item to be removed from the
cart:";
cin>>temp;
for(i=0;name[i][0]!='\0'&&temp!=code[i];i++);
if(code[i]==temp)
{amount-=quant[i]*price[i];
amount-=(tax(amount)+vat(amount));
quant[i]=0;
cout<<"\n\t\t\t Removed from the cart";}
else
cout<<"\n\t\t\t\a Code not found";
getch();
break;
case '3': do{clrscr();
cout<<"\n\t\t\t Your cart!";
cout<<"\n\n Code\t\tName\t\tPcs.\tCost per unit\tTotal price";
for(i=0;name[i][0]!='\0';i++)
{if(quant[i])
{cout<<"\n\n"<<code[i]<<"\t";
cout.width(16);
cout<<name[i];
cout<<"\t"<<quant[i]<<"\t
"<<price[i]<<"\t\t"<<quant[i]*price[i];}
}
cout<<"\n\n\t\t\t\t\t\t\tTax=
"<<tax(amount)<<"\n\t\t\t\t\t\t\tVAT= "<<vat(amount);
cout<<"\n\t\t\t\t\t\t\tTotal= "<<amount;
cout<<"\n\n\t\t\t What do you want to
do?\n\n\t\t(1)Confirm\t\t(2)Go back\n\n\t\t\tYour choice:";
choice1=getch();