#include<iostream>
#include<iomanip>
#include<cmath>
#include<fstream>
#include<algorithm>
#include<string>
using namespace std;
int sizeOfPro=0;
struct menu
{
	string product, pices,id,price,discont;
} ;
double calculate (menu arr[])
{
double sum=0;
	for (int i =0 ; i<sizeOfPro; i++)
	{ 
		double pri= stod(arr[i].price), num=stod(arr[i].pices),dis=stod(arr[i].discont );
		if(dis>0)
		sum +=(pri*num)-(pri*num)*(dis/100);
		else
			sum+=pri*num;
	}
	return sum;
}
void  add_request(menu arr [])
{
	bool d =false, n= false, p=false , b=false,cos=false;
	int c=0,f=0;
	cout<<"\n please id of item   ";
	cin>>arr[sizeOfPro].id;
	for (int j=0;j<sizeOfPro;j++)
	{
	  if (arr[j].id!=arr[sizeOfPro].id)
		  continue;
	  else																						
	  {
	    c++;
		d=false;
		break;
	  }
	}
	if(c==0)
	{
		for (int i=0 ;i<arr[sizeOfPro].id.size();i++)
	{
		if (arr[sizeOfPro].id[i]<='9'&&arr[sizeOfPro].id[i]>='0')
			  d=true;
		     else
			 {
			   d=false;
			    break;
		     }
	}
	}
	cout <<"\n enter name item you want  ";
	cin>>arr[sizeOfPro].product;
	{
		for (int i=0 ;i<arr[sizeOfPro].product.size();i++)
		{
			if (arr[sizeOfPro].product[i]>='A'&&arr[sizeOfPro].product[i]<='Z'||arr[sizeOfPro].product[i]>='a'&&arr[sizeOfPro].product[i]<='z')
			{
				n=true;
			}
			else
			{
				n=false;
				break;
			}
		}
	}
	cout<<"\nenter price of this item   ";
	cin>>arr[sizeOfPro].price;
	if (arr[sizeOfPro].price=="0")
		p=false;
	else
	{	for (int i=0 ;i<arr[sizeOfPro].price.size();i++)
	{
		if ((arr[sizeOfPro].price[i]<='9'&&arr[sizeOfPro].price[i]>='0')||arr[sizeOfPro].price[i]=='.')
		{
			p=true;
		}
		else
		{
			p=false;
			break;  
		}
	}
	}
	cout<<"\nenter number of pieces you want   ";
	cin>>arr[sizeOfPro].pices; // add product and how many pieces and there prises 
	if (arr[sizeOfPro].pices=="0")
		{
			b=false;
	    }
	     else
		 {for (int i=0 ;i<arr[sizeOfPro].pices.size();i++) 
		
			{
				if ((arr[sizeOfPro].pices[i]<='9'&&arr[sizeOfPro].pices[i]>='0')||arr[sizeOfPro].pices[i]=='.')
				{
					b=true ; 
				}
				else
				{
					b=false;
					break;  
				}
			}
		}
		cout<<"\n enter your discont   ";
		cin>>arr[sizeOfPro].discont;
			for (int i=0 ;i<arr[sizeOfPro].pices.size();i++)
			{
				if ((arr[sizeOfPro].discont[i]<='9'&&arr[sizeOfPro].discont[i]>='0')||arr[sizeOfPro].discont[i]=='.'||arr[sizeOfPro].discont[i]=='%')
				{
					cos=true ; 
				}
				else
				{    f++;
					cos=false;
					break;  
				}
			}
		   if (f==0)
		   {
		   if (stod(arr[sizeOfPro].discont)<100)
			   cos=true;
		   else
			   cos=false;
		   
		   }
		
		if (d==true &&p==true &&n==true&&b==true &&cos==true)
			{

				sizeOfPro++;
				}
		else  if(d==false ||p==false ||n==false||b==false||cos==false)
			{
				if (d==false)
					cout<<"id ";
				 if (n==false)
					cout<<"  product ";
				 if (p==false)
					cout<<"  price";
				 if (b==false)
					cout<<"  pices";
				 if (cos==false)
					cout<<"  discont";
				    cout<<"\  the error again\n";
				
               }
}
void  delet(int itemdel,menu arr[])
{
	bool sign=false;
	for (int i=itemdel-1;i<sizeOfPro;i++)
	{
		arr[i]=arr[i+1];
		
		sign=true ;
	} 
	if ( sign==true)
		{
			cout<<"\n done delete the item successfully\n";
			sizeOfPro--;
	}
	else
		cout<<"\nwe donot find thise item\n ";
}// take number of item want to delete and the list 
void the_list(menu arr[],string a)
{
	int b=sizeOfPro;
	if(b>0)
	{cout<<"\n the name :"<<a;
	if  (sizeOfPro>=0)
	{
		for (int i =0 ; i<sizeOfPro; i++)
			cout<<"\nthe id of item :  \t"<<arr[i].id<<"    the item name: \t"<<arr[i].product<<"   the price:\t"<<arr[i].price<<" number of pices:\t "<<arr[i].pices<<"the discont\t"<<arr[i].discont<<"\n_________________________________________________"<<endl;
	}
	}
	else 
		cout<<"\n No requests yet\n ";
}
menu arr[10000];
int main ()
{
	string name,y;
	char x ;
	int e=0;
	cout<<"\n please enter your name ^_^ \n";
	cin>>name;
	menu  arr[1000];
	do
	{
		system("pause");
		system("Color B2");
		system("CLS");
		cout <<"\n          ^ _ ^  Welcome in my Resturant ^ _ ^ \t"<<name<<"\n";
		cout << "\n 1:to add  element";
		cout <<"\n 2:to deldete element ";
		cout<<"\n 3: to show the list of item ";
		cout<<"\n 4: to calculate the total bill";

		cout <<"\n 5: to exite";
		cout << "\n what is your next option ";
		cin>>x;
		  x=x-'0';
		switch (x)
		{
		case 1: system("Color B2"),add_request(arr) ; break;
		case 2:
			{
			system("Color B2");
			cout<< " the number  of you want delet : ";
			cin>>y ;for (int i=0 ; i< y.size();i++)
			    {if (y[i]<='9'&&y[i]>='0')
			       continue;
			      else
				  {	e++;
			      break;
		       }
			}
			if (e==0&&stoi(y)>0)
				delet(stoi(y),arr);
			else
			cout<<"\n try again ^ _ ^\n";

		}
		case 3: the_list(arr,name);break;
		case 4:{ system("Color B2");
			      the_list(arr,name);
				   cout<<"bill = \t"<<calculate(arr)<<"\nthank you ^_^ \n";
			       break;
			   }
		case 5 : return 0;break ;
		default :cout << "error\n";
		}
	}
	while (true);
	return 0;
}