FOR DETAILED EXPLANATION : VIDEO
----------------------------------------------------------------------------------------------------------------------
Please watch the video,your views mean a lot!
========================================================================
#include<iostream>
using namespace std;
class item
{
long id;
long cost;
long stock;
public:
void read()
{
cin>>id;
cin>>cost;
cin>>stock;
}
int check(int n)
{
if(n==id)
return 1;
else
throw(0);
}
int costcheck(int n)
{
if(n>cost)
return 1;
else
throw(0.0);
}
int stockcheck()
{
if(stock>=1)
return 1;
else
throw string("ERROR");
}
void display()
{
cout<<id;
}
};
int main()
{
int n;
cin>>n;
item I[n];
for(int i=0;i<n;i++)
{
I[i].read();
}
int it,c;
cin>>it;
cin>>c;
int c2=0;
//cout<<"\n";
for(int i=0;i<n;i++)
{
try
{
I[i].check(it);
I[i].costcheck(c);
I[i].stockcheck();
I[i].display();
}
catch(int i)
{
c2++;
}
catch(double k)
{
cout<<"Insufficient amount"<<endl;
break;
}catch(string a)
{
cout<<"Less stock"<<endl;
break;
}
}
if(c2==n)
cout<<"Wrong item code";
return 0;
}
----------------------------------------------------------------------------------------------------------------------
Please watch the video,your views mean a lot!
========================================================================
#include<iostream>
using namespace std;
class item
{
long id;
long cost;
long stock;
public:
void read()
{
cin>>id;
cin>>cost;
cin>>stock;
}
int check(int n)
{
if(n==id)
return 1;
else
throw(0);
}
int costcheck(int n)
{
if(n>cost)
return 1;
else
throw(0.0);
}
int stockcheck()
{
if(stock>=1)
return 1;
else
throw string("ERROR");
}
void display()
{
cout<<id;
}
};
int main()
{
int n;
cin>>n;
item I[n];
for(int i=0;i<n;i++)
{
I[i].read();
}
int it,c;
cin>>it;
cin>>c;
int c2=0;
//cout<<"\n";
for(int i=0;i<n;i++)
{
try
{
I[i].check(it);
I[i].costcheck(c);
I[i].stockcheck();
I[i].display();
}
catch(int i)
{
c2++;
}
catch(double k)
{
cout<<"Insufficient amount"<<endl;
break;
}catch(string a)
{
cout<<"Less stock"<<endl;
break;
}
}
if(c2==n)
cout<<"Wrong item code";
return 0;
}
#include
ReplyDelete#include
using namespace std;
struct details
{ char code[20];
int cost;
int stock;
}d[10];
int main()
{ int n;
char cd[20];
int price;
cin>>n;
for(int i=0;i>d[i].code;
cin>>d[i].cost;
cin>>d[i].stock;
}
cin>>cd>>price;
for(int i=0;i=d[i].cost) && (d[i].stock>0) )
{cout<=d[i].cost) && (d[i].stock<=0))
{cout<<"Less stock"; break;}
else
{cout<<"Wrong item code";break;}
}
return 0;}
//hidden text error
Code looks incomplete.
DeleteMoreover your for loops have incomplete braces and double initializing of i.I am unable to comprehend. Logic doesn't seem to be right .Please clearify.