#include <iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<unordered_map>
using namespace std;
class inventory{
public:
map<string,int>m;
inventory(){
m.emplace("TV",100);
m.emplace("HDTV",75);
m.emplace("HP LAPTOP",45);
m.emplace("PLAYSTATION 5",30);
m.emplace("NINTENDO SWITCH 2",60);
}
string toUpper(string str) {
transform(str.begin(), str.end(), str.begin(), ::toupper);
return str;
}
void order( ){
while(true){
cout<<" what do you want to order ?"<<endl;
string s;
cin >> ws; // remove leading spaces
getline(cin, s); // allow spaces in product names
s = toUpper(s);
if(s=="EXIT"){
cout<<" thank you for shopping "<<endl;
exit(0);
}
if(m.find(s)!=m.end()){
cout<<" your order is "<<s<<endl;
}
else{
cout<<" your order is invalid "<<endl;
}
cout<<" enter the quantity of your order "<<endl;
int q;
cin>>q;
if(q<=0){
cout<<" invalid quantity "<<endl;
return;
}
if(q>m[s]){
cout<<"Sorry we have "<<m[s]<<" stock only ";
return;
}
m[s] -= q;
cout << "Quantity of your order is " << q << endl;
cout << "Remaining quantity is " << m[s] << endl;
}
}
};
int main() {
inventory I;
I.order();
return 0;
}
No comments:
Post a Comment