Finding Numbers in string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

4th Sep 2018, 1:26 AM
Harry
Harry - avatar
4 Answers
+ 1
Harry could you please elaborate? I am sorry to say but not getting what you want to achieve and ask
4th Sep 2018, 5:11 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 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
4th Sep 2018, 10:48 AM
Harry
Harry - avatar
4th Sep 2018, 3:28 PM
Harry
Harry - avatar
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
4th Sep 2018, 12:26 PM
Ketan Lalcheta
Ketan Lalcheta - avatar