Question: I need help, when I put the preloaded user, the program works normally, but I need that if I put a wrong user it gives
I need help, when I put the preloaded user, the program works normally, but I need that if I put a wrong user it gives me the option to add user, and asks me for the user again, so when I put the one I added as new, it works normally.
Here my code
int main
vector items
ItemPaper
ItemFeather
ItemLaptop
ItemPencil
ItemDraft
;
vector cart;
string inputUser, inputPass;
cout "User: ;
cin inputUser;
cout "Password: ;
cin inputPass;
if User::validateUserinputUser inputPass
cout Welcome to my online store choice;
switch choice
case :
int subChoice;
cout View items below a certain price" endl;
cout View items above a certain price" endl;
cout Search by name" endl;
cout "Enter your choice: ;
cin subChoice;
if subChoice subChoice
double priceLimit;
cout "Enter price limit: ;
cin priceLimit;
cout "Available items:
;
for int i ; i items.size; i
if subChoice && itemsigetPrice priceLimitsubChoice && itemsigetPrice priceLimit
cout i itemsigetName Price: $ itemsigetPrice endl;
else if subChoice
string itemName;
cout "Enter item name: ;
cin itemName;
for const auto & item : items
if itemgetName itemName
cout "Item: item.getName Price: $ item.getPrice endl;
char addToCart;
cout Do you want to add an item to your cart? YN: ;
cin addToCart;
if addToCart Y addToCart y
int itemNumber;
int itemQuantity;
cout "Enter item number: ;
cin itemNumber;
cout "Enter the amount: ;
cin itemQuantity;
if itemNumber && itemNumber items.size
itemsitemNumber setQuantityitemQuantity;
cart.pushbackitemsitemNumber ;
cout "Item added to cart." endl;
else
cerr "Invalid item number." endl;
string cont;
cout Do you want to exit to the main menu or continue adding items?MenuAdd: ;
cin cont;
while cont "Add"
int itemNum, qty;
cout "Enter item number: ;
cin itemNum;
cout "How many pieces?";
cin qty;
itemsitemNum setQuantityqty;
cart.pushbackitemsitemNum ;
cout "Item added to cart.
;
cout Do you want to exit to the main menu or continue adding items?MenuAdd: ;
cin cont;
break;
case :
cout "Your cart:" endl;
double total ;
for sizet i ; i cart.size; i
cout i cartigetName Price: $ cartigetPrice Quantity: cartigetQuantity endl;
total cartigetPrice cartigetQuantity;
cout "Total cost: $ total endl;
string checkout;
cout Do you want to pay or continue shopping?? PayContinue: ;
cin checkout;
if checkout "Checkout"
cout "Press Ok to close the sale..
;
string Ok;
cin Ok;
if Ok Ok
cout "Sale successfully closed. Thank you for shopping with us endl;
cart.clear;
break;
case :
cout "Goodbye!" endl;
break;
default:
cerr "Invalid choice." endl;
break;
while choice ;
else
cerr "Unregistered user." endl;
cout endl;
string register;
cin register;
if register
string username, password;
cout "Enter your username: ;
cin username;
cout "Enter your password: ;
cin password;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
