0
Finding Numbers in string
I would like to know how I would do something where instead of the user inputting the numbers they would like to add ex. if (Input == "add") { cout << "Enter 2 numbers to add" << endl; cin >> Num1; cin >> Num2; } } And instead if the user inputted "Add 1 and 2" it would add 1 and 2 together without there having to be an if statement and then input 2 numbers at separate times.
4 ответов
+ 1
Harry could you please elaborate? I am sorry to say but not getting what you want to achieve and ask
+ 1
Ketan Lalcheta im saying that instead of making an if statement, i could find the 2 numbers in the users input. instead of having them say add and then input the 2 numbers seperately so if the user just inputted "add 1 and 2" i could find the 2 numbers in that string
+ 1
Ketan Lalcheta yes
0
Harry ok..correct me if I misunderstood...
you can ask user to input one string... use getline instead of fun which allows you to provide input with space...
split spring with space and take input in two intereger and one string for add type of value.. perform addition for two numbers and show results