0
Can I implement a Default function in C++ Maps
I redo all easy Code Coach Challenges with c++ at the moment and Test some functions. Does someone know a simple way to give "Coke" as a Kind of Default Case in that Code. https://code.sololearn.com/cSke88tdptn0/?ref=app
5 Réponses
+ 1
Felix
You can add a function or lambda in the code. It basically searches the map for a key, returns the price of the relevant item when found, or the coke's price when not.
You can also make the function/lambda to accept just the 4 items given in test, or make it accept a string container, then use loop to search the map for each item in the string container (more flexible than a fixed 4 parameters).
I think you got this!
+ 2
No worries, I see you catching up pretty quick. Like I said, you got this, and I was right ... 😁
+ 1
Ipang I didn't entirely understand what you meant in the first part (just started c++ 4-6 hours ago 😉). For the second I didn't want to redo what I did with c# and Experiment a bit.
So but now I'm finished I Made a search methode to search for the elements in the map else return value of Coke.
https://code.sololearn.com/c73WEibmSJ7T/?ref=app
+ 1
Felix
That was also what I had in mind with the function.
Good job! 👍
+ 1
Needed a bit longer to understand the find function.