- 1
Converting a users string input into a number output
I can't seem to find anything about this in the tutorial. Example:user enters "cheeseburger" string and i want to output the i integer price as 4
2 Answers
+ 1
I know what you want to make, the Challenge about Cheeseburger, Nachos and such.
I would recommend you using
C++ map fuction, it's a list which gets two Inputs one "Key" and one "value", So as example you can put "Cheeseburger" as Key and the Price as "value".
Read more about map Here:
https://docs.microsoft.com/en-us/cpp/standard-library/map-class?view=msvc-170
edit:
little example for map:
map<string, int> MyMap =
{
{"One", 1},
{"Two", 2},
{"Three", 3}
}
str input;
cin >> input;
cout << (input + "=" +MyMap[input]);
//Output by Case: "One" = 1
//Two = 2
//Three = 3
- 1
Could you elaborate more?